iOS: Ken Burns animation implementation requires unexpected parameters
I have a UIImageView I'm trying to animate a Ken Burns-like pan/zoom on. I want to start centered on a face (specifically, say, the end of the person's nose) and zoom out to the full size of the image. The code is something like:
image.frame = // some frame that zooms in on the image;
image.center = // tip of the nose
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
image.frame = // original frame
image.center = // original centerpoint
[UIView commitAnimations];
In Photoshop the tip o开发者_如何学JAVAf the nose's coordinates are completely different from the values I've had to punch into the above code to actually center the image on the nose when the animation begins. I have tried reflecting the axes, multiplying by a factor of the scale... and I cannot seem to figure out why iOSs numbers are significant v. the ones I deduced from Photoshop.
Can someone point out the discrepancy between the two coordinate systems?
Some additional information:
image
is a UIImageView and is an immediate child of a UIViewController- Said UIViewController is oriented horizontally - the entire app runs in landscape mode.
Setting both frame and center is a bit redundant. The frame should suffice, using both you're losing some part of the setup.
EDIT: More precisely, you should have only two frames to setup and let CoreAnimation do the rest.
The problem is that animation happens in some complex way. It doesn't matter how exactly, but results to this. You can't set initial parameters and animate them in one method. You have to setup initial parameters, then send [self performSelector:withObject:afterDelay:] message where animation will happen (all [UIView *animation] messages).
So your code will look like this.
- (void)one {
image.frame = // some frame that zooms in on the image;
image.center = // tip of the nose
[self performSelector:@selector(two) withObject:nil afterDelay:0];
}
- (void)two {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
image.frame = // original frame
image.center = // original centerpoint
[UIView commitAnimations];
}
精彩评论