iOS:Ken Burns 动画实现需要意外参数
我有一个 UIImageView,我正在尝试为类似 Ken Burns 的平移/缩放设置动画。我想以脸部为中心(特别是人的鼻子末端)开始,然后缩小到图像的完整尺寸。代码类似于:
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];
在 Photoshop 中,鼻尖的坐标与动画开始时我必须输入上述代码以实际将图像置于鼻子中心的值完全不同。我尝试过反映轴,乘以比例因子......但我似乎无法弄清楚为什么 iOS 的数字与我从 Photoshop 推导出的数字相比很重要。
有人可以指出两个坐标系之间的差异吗?
一些附加信息:
image
是一个 UIImageView,并且是 UIViewController 的直接子级。- 所述 UIViewController 是水平定向的 - 整个应用程序以横向模式运行。
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 of 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
同时设置框架和中心有点多余。框架应该足够了,使用两者你都会丢失设置的某些部分。
编辑:更准确地说,您应该只需要设置两个帧,然后让 CoreAnimation 完成其余的工作。
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.
问题在于动画以某种复杂的方式发生。具体如何并不重要,重要的是结果。您无法通过一种方法设置初始参数并为其设置动画。您必须设置初始参数,然后发送 [self PerformSelector:withObject:afterDelay:] 消息,其中动画将发生(所有 [UIView *animation] 消息)。
所以你的代码将如下所示。
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.