Thursday, 15 May 2014

xcode - Dynamically changing lineWidth using UISlider? -



xcode - Dynamically changing lineWidth using UISlider? -

i have imported crumbpath.h & .m , crumpathview.h & .m project sample code provided apple.

it working fine, until want command linewidth of crumbpath, in previous question solved how utilize value 'sliderchanged' populate 'cgfloat linewidth ='

linked here: use value uislider alter variable?

now have nail problem line not showing @ in simulator...

crumbpathview.m

#import "crumbpathview.h" #import "crumbpath.h" #import "firstviewcontroller.h" @interface crumbpathview (fileinternal) - (cgpathref)newpathforpoints:(mkmappoint *)points pointcount:(nsuinteger)pointcount cliprect:(mkmaprect)maprect zoomscale:(mkzoomscale)zoomscale; @end @implementation crumbpathview -(ibaction)sliderchanged:(uislider *)sender { } - (void)drawmaprect:(mkmaprect)maprect zoomscale:(mkzoomscale)zoomscale incontext:(cgcontextref)context { crumbpath *crumbs = (crumbpath *)(self.overlay); cgfloat linewidth = self.sliderchanged.value; // outset map rect line width points outside // of drawn rect included in generated path. mkmaprect cliprect = mkmaprectinset(maprect, -linewidth, -linewidth); [crumbs lockforreading]; cgpathref path = [self newpathforpoints:crumbs.points pointcount:crumbs.pointcount cliprect:cliprect zoomscale:zoomscale]; [crumbs unlockforreading]; if (path != nil) { cgcontextaddpath(context, path); cgcontextsetrgbstrokecolor(context, 0.0f, 0.0f, 1.0f, 0.5f); cgcontextsetlinejoin(context, kcglinejoinround); cgcontextsetlinecap(context, kcglinecapround); cgcontextsetlinewidth(context, linewidth); cgcontextstrokepath(context); cgpathrelease(path); } } @end @implementation crumbpathview (fileinternal) static bool lineintersectsrect(mkmappoint p0, mkmappoint p1, mkmaprect r) { double minx = min(p0.x, p1.x); double miny = min(p0.y, p1.y); double maxx = max(p0.x, p1.x); double maxy = max(p0.y, p1.y); mkmaprect r2 = mkmaprectmake(minx, miny, maxx - minx, maxy - miny); homecoming mkmaprectintersectsrect(r, r2); } #define min_point_delta 5.0 - (cgpathref)newpathforpoints:(mkmappoint *)points pointcount:(nsuinteger)pointcount cliprect:(mkmaprect)maprect zoomscale:(mkzoomscale)zoomscale { // fastest way draw path in mkoverlayview simplify // geometry screen eliding points close // , omit line segments not intersect clipping rect. // while possible add together points , allow coregraphics // handle clipping , flatness, much faster yourself: // if (pointcount < 2) homecoming null; cgmutablepathref path = null; bool needsmove = yes; #define pow2(a) ((a) * (a)) // calculate minimum distance between 2 points figuring out // how many map points correspond min_point_delta of screen points // @ current zoomscale. double minpointdelta = min_point_delta / zoomscale; double c2 = pow2(minpointdelta); mkmappoint point, lastpoint = points[0]; nsuinteger i; (i = 1; < pointcount - 1; i++) { point = points[i]; double a2b2 = pow2(point.x - lastpoint.x) + pow2(point.y - lastpoint.y); if (a2b2 >= c2) { if (lineintersectsrect(point, lastpoint, maprect)) { if (!path) path = cgpathcreatemutable(); if (needsmove) { cgpoint lastcgpoint = [self pointformappoint:lastpoint]; cgpathmovetopoint(path, null, lastcgpoint.x, lastcgpoint.y); } cgpoint cgpoint = [self pointformappoint:point]; cgpathaddlinetopoint(path, null, cgpoint.x, cgpoint.y); } else { // discontinuity, lift pen needsmove = yes; } lastpoint = point; } } #undef pow2 // if lastly line segment intersects maprect @ all, add together unconditionally point = points[pointcount - 1]; if (lineintersectsrect(lastpoint, point, maprect)) { if (!path) path = cgpathcreatemutable(); if (needsmove) { cgpoint lastcgpoint = [self pointformappoint:lastpoint]; cgpathmovetopoint(path, null, lastcgpoint.x, lastcgpoint.y); } cgpoint cgpoint = [self pointformappoint:point]; cgpathaddlinetopoint(path, null, cgpoint.x, cgpoint.y); } homecoming path; } @end

crumbpathview.h

#import <mapkit/mapkit.h> #import <uikit/uikit.h> @interface crumbpathview : mkoverlayview { } @property (weak, nonatomic) iboutlet uislider *sliderchanged; @end

when moving slider output console logs changes, nil changes visually. no errors, mentioned crumbpath not showing @ all... if linewidth set '0'.

xcode uislider mapkit

No comments:

Post a Comment