ios - Problems setting position of CAShapelayer -
i have posted similar question before didn't feel got correct answer. want change position of cashapelayer
position of touch located when touch moved. i'm using code can see down below. problem have animation work, not touch located. instead 20 pixels away. there way fix this?
-(void)touchesbegan:(nsset *)touches withevent:(uievent *)event { nsset *alltouches = [event alltouches]; uitouch *touch = [alltouches objectatindex:0]; cgpoint currentpos = [mytouch locationinview: self]; layer = [self addcircleyellownwithradius:8 withduration:5 x:currentpos.x y:currentpos.y]; } -(void)touchesmoved:(nsset *)touches withevent:(uievent *)event { nsset *alltouches = [event alltouches]; uitouch *touch = [alltouches objectatindex:0]; cgpoint currentpos = [mytouch locationinview: self]; //set layer posotion touch position layer.position = cgpointmake(currentpos.x-8,currentpos.y-8); } -(cashapelayer *)addcircleyellownwithradius:(float)radius5 withduration:(float)duration x:(float)x y:(float)y{ int radius = (int)radius5; cashapelayer *circle = [cashapelayer layer]; // make circular shape circle.path = [uibezierpath bezierpathwithroundedrect:cgrectmake(0, 0, 2.0*radius, 2.0*radius) cornerradius:radius].cgpath; // center shape in self.view circle.position = cgpointmake(x-radius, y-radius); // configure apperence of circle circle.fillcolor = [uicolor clearcolor].cgcolor; circle.strokecolor = [uicolor whitecolor].cgcolor; circle.linewidth = 5; // add parent layer [self.view.layer addsublayer:circle]; // configure animation cabasicanimation *drawanimation = [cabasicanimation animationwithkeypath:@"strokeend"]; drawanimation.duration = duration; // "animate on 10 seconds or so.." drawanimation.repeatcount = 1.0; // animate once.. // animate no part of stroke being drawn entire stroke being drawn drawanimation.fromvalue = [nsnumber numberwithfloat:0.0f]; drawanimation.tovalue = [nsnumber numberwithfloat:1.0f]; // experiment timing appearence way want drawanimation.timingfunction = [camediatimingfunction functionwithname:kcamediatimingfunctioneasein]; // add animation circle [circle addanimation:drawanimation forkey:@"drawcircleanimation"]; cgrect oldframe = circle.frame; circle.anchorpoint = cgpointmake(0.5, 0.5); circle.frame = oldframe; return circle; }
Comments
Post a Comment