iphone - Xcode Rotate image torwads a CGPoint without transform -
i made app: got image , follows finger ever moving it. want rotate towards cgpoint
.
i tested things , when tried @ first transform image jumped original position, rotated , continued following finger.
how rotate without transform (or if know how fix said it's good) ?
my code =
//this called every 0.01 seconds cgpoint center = self.im.center; if (!cgpointequaltopoint(self.im.center, i)) { x = center.x; y = center.y; double distance = sqrtf(powf(i.x - x, 2) + powf(i.y - y, 2)); float speedx = (2 * (i.x - x)) / distance; float speedy = (2 * (i.y - y)) / distance; //float degree = (angle) % 360; //self.im.center = cgpointmake(center.x+speedx, center.y+speedy); cgaffinetransform translate = cgaffinetransformmaketranslation(center.x+speedx, center.y+speedy); cgaffinetransform rotate = cgaffinetransformmakerotation(angle); [self.im settransform:cgaffinetransformconcat(rotate, translate)]; } -(void)touchesmoved:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [touches anyobject]; = [touch locationinview:self.view]; angle = atan2f(self.im.center.y-i.y, self.im.center.x-i.x); //[self.im settransform:cgaffinetransformrotate(self.im.transform, angle)]; } -(void)touchesbegan:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [touches anyobject]; i=[touch locationinview:self.view]; angle = atan2f(self.im.center.y-i.y, self.im.center.x-i.x); }
you can apply number of transformations image view cgaffinetransformconcat. like:
cgaffinetransform translate = cgaffinetransformmaketranslation(dx, dy); cgaffinetransform rotate = cgaffinetransformmakerotation(angle); [yourimageview settransform:cgaffinetransformconcat(rotate, translate)];
Comments
Post a Comment