Reputation: 5001
I would like to move a UIImageview from point A to B in certain degree. the Red and Blue arrow denote the degree i want the dots to move.
i can move the dots from one point to another, but how do i move the note on a degree ?
NSLog(@"cgpoint %@",NSStringFromCGPoint(self.aggressiveDots.frame.origin));
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], nil];
[anim setKeyTimes:times];
NSArray *values = [NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(118, 188.)],
[NSValue valueWithCGPoint:CGPointMake(115, 300.)], nil];
[anim setValues:values];
[anim setDuration:6.0]; //seconds
[self.redDots.layer addAnimation:anim forKey:@"position"];
Upvotes: 1
Views: 213
Reputation: 28756
Since you'd like to move the UIView along a straight line (not a curve) you only need two points for your CAKeyFrameAnimation - the starting and endoing point. In fact you could even use [UIView transistionWithView:] for this if you wanted - just manipulate the frame in the animation block.
If you'd like to avoid tricky algebra, you can draw a triangle as follows:
"In general, x
and y
must satisfy (x - center_x)^2 + (y - center_y)^2 < radius^2
"
Upvotes: 1