ios - Draw on UIImageView over MKMapView -


i have searched lot answer question, none of them seem want. lot of tutorials show me how add lines , polygons in code, not freehand drawing.

i got mkmapview uiimageview on map. , can draw little on uiimageview right after that, mkmapview draged , draw doesn't continue.

i know have done wrong ?

here code touches events :

- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event {     uitouch *touch = [touches anyobject];     pointa = [touch locationinview:drawview]; }  - (void)touchesmoved:(nsset *)touches withevent:(uievent *)event {         uitouch *touch = [touches anyobject];         cgpoint currentlocation = [touch locationinview:drawview];          uigraphicsbeginimagecontext(drawview.frame.size);         cgcontextref ctx = uigraphicsgetcurrentcontext();         [drawview.image drawinrect:cgrectmake(0, 0, drawview.frame.size.width, drawview.frame.size.height)];         cgcontextsetlinecap(ctx, kcglinecapround);         cgcontextsetlinewidth(ctx, 5.0);         cgcontextsetrgbstrokecolor(ctx, 1.0, 0.0, 0.0, 1.0);         cgcontextbeginpath(ctx);         cgcontextmovetopoint(ctx, pointa.x, pointa.y);         cgcontextaddlinetopoint(ctx, currentlocation.x, currentlocation.y);         cgcontextstrokepath(ctx);         drawview.image = uigraphicsgetimagefromcurrentimagecontext();         uigraphicsendimagecontext();          pointa = currentlocation; }  - (void)touchesended:(nsset *)touches withevent:(uievent *)event {         uitouch *touch = [touches anyobject];         cgpoint currentlocation = [touch locationinview:drawview];          uigraphicsbeginimagecontext(drawview.frame.size);         cgcontextref ctx = uigraphicsgetcurrentcontext();         [drawview.image drawinrect:cgrectmake(0, 0, drawview.frame.size.width, drawview.frame.size.height)];         cgcontextsetlinecap(ctx, kcglinecapround);         cgcontextsetlinewidth(ctx, 5.0);         cgcontextsetrgbstrokecolor(ctx, 1.0, 0.0, 0.0, 1.0);         cgcontextbeginpath(ctx);         cgcontextmovetopoint(ctx, pointa.x, pointa.y);         cgcontextaddlinetopoint(ctx, currentlocation.x, currentlocation.y);         cgcontextstrokepath(ctx);         drawview.image = uigraphicsgetimagefromcurrentimagecontext();         uigraphicsendimagecontext();          pointa = currentlocation; }  

and code of button show uiimageview :

edit : made stoping interactions map :

- (ibaction)modedraw:(id)sender {     if (drawview.alpha == 0.0) {         drawview.image=nil; //empty new draw         drawview.backgroundcolor = [uicolor whitecolor];         [uiimageview beginanimations:nil context:nil];         [uiimageview setanimationduration:0.5];         [drawview setalpha:0.4];         [uiimageview commitanimations];         mymapview.zoomenabled = no;         mymapview.scrollenabled = no;     } else {         [uiimageview beginanimations:nil context:nil];         [uiimageview setanimationduration:0.5];         [drawview setalpha:0.0];         [uiimageview commitanimations];         mymapview.zoomenabled = yes;         mymapview.scrollenabled = yes;     } } 

after doing draw, i transform draw form (area), put on map. if have indications me ?

thank you, , sorry bad english.

here code if have same problem me , link allan gave me : http://www.apps168.net/post/1460.html :

- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event {     uitouch *touch = [touches anyobject];     pointa = [touch locationinview:drawview];     pathref = cgpathcreatemutable();     cgpathmovetopoint(pathref, null, pointa.x, pointa.y); }  - (void)touchesmoved:(nsset *)touches withevent:(uievent *)event {     uitouch *touch = [touches anyobject];     cgpoint currentlocation = [touch locationinview:drawview];     cgpoint pastlocation = [touch previouslocationinview:drawview];      uigraphicsbeginimagecontext(drawview.frame.size);     cgcontextref ctx = uigraphicsgetcurrentcontext();     [drawview.image drawinrect:cgrectmake(0, 0, drawview.frame.size.width, drawview.frame.size.height)];     cgcontextsetlinecap(ctx, kcglinecapround);     cgcontextsetlinewidth(ctx, 5.0);     cgcontextsetrgbstrokecolor(ctx, 0.0, 0.0, 0.0, 1.0);     cgcontextbeginpath(ctx);     cgcontextstrokepath(ctx);      cgcontextmovetopoint(ctx, pastlocation.x, pastlocation.y);     cgcontextaddlinetopoint(ctx, currentlocation.x, currentlocation.y);     cgcontextdrawpath(ctx, kcgpathfillstroke);     drawview.image=uigraphicsgetimagefromcurrentimagecontext();      cgpathaddlinetopoint(pathref, null, currentlocation.x, currentlocation.y);     uigraphicsendimagecontext();      //pointa = currentlocation; }  - (void)touchesended:(nsset *)touches withevent:(uievent *)event {      cgpathclosesubpath(pathref);      nsuinteger count = [array count];     (nsuinteger = 0; < count; i=i+2) {         nsstring *lat = [array objectatindex: i];         nsstring *lgt = [array objectatindex: i+1];          cllocationcoordinate2d pointloc;         pointloc.latitude = [lat doublevalue];         pointloc.longitude = [lgt doublevalue];          locationconvertoimage = [mymapview convertcoordinate:pointloc topointtoview:drawview];         if (cgpathcontainspoint(pathref, null, locationconvertoimage, no)) {             nslog(@"point in path!");             //sélection de ces points et cacher les autres.         }     }      [uiimageview beginanimations:nil context:nil];     [uiimageview setanimationduration:0.5];     [drawview setalpha:0.0];     [uiimageview commitanimations];     mymapview.zoomenabled = yes;     mymapview.scrollenabled = yes;  } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -