如何通过旋转正确设置子视图中心点的动画
我有两个 UIViews(A 和 B)作为 subviews
添加到 UIViewcontroller
Main View
(超级视图) 。
我正在尝试对View A
进行动画处理(缩放/旋转/移动中心点到View B
)。如果我进行缩放/旋转,动画就会很流畅。如果我只做中心点,动画就会很流畅。但是,当我尝试包括更改 View A
的中心点、旋转和缩放时,View A
的中心点动画是即时且不稳定的,但是旋转/缩放很顺利。
这是我的动画块:
[UIView animateWithDuration:2.0
animations:^ {
self.customView.frame = CGRectMake(self.containerSubview.frame.origin.x, self.containerSubview.frame.origin.y, 200, 300);
self.containerSubview.alpha = 0.2;
self.customView.transform = CGAffineTransformConcat(CGAffineTransformMakeRotation(M_PI / 2), CGAffineTransformMakeScale(1.5, 1.5));
self.customView.center = self.containerSubview.center;
}
completion:^(BOOL finished) {
NSLog(@"center point: %@", NSStringFromCGPoint(self.customView.center));
}
];
I have two UIViews
(A and B) are added as subviews
to a UIViewcontroller
Main View
(the superview).
I am trying to animate View A
(scale/rotate/move center point to that of View B
). If I do the scale/rotate the animation is smooth. If I just do the center point the animation is smooth. However, when I try to include changing the center point, rotation and scaling of View A
then View A
's center point animation is instant and jerky, but the rotation/scaling is smooth.
Here is my animation block:
[UIView animateWithDuration:2.0
animations:^ {
self.customView.frame = CGRectMake(self.containerSubview.frame.origin.x, self.containerSubview.frame.origin.y, 200, 300);
self.containerSubview.alpha = 0.2;
self.customView.transform = CGAffineTransformConcat(CGAffineTransformMakeRotation(M_PI / 2), CGAffineTransformMakeScale(1.5, 1.5));
self.customView.center = self.containerSubview.center;
}
completion:^(BOOL finished) {
NSLog(@"center point: %@", NSStringFromCGPoint(self.customView.center));
}
];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当涉及到转换时,我应该更仔细地阅读文档。由于变换取决于视图的中心点。我无法在 uiview 级别同时发生修改变换和中心的动画。由于中心是变换的依赖项,因此必须立即设置,然后才能发生其余的动画。
解决方案是在视图层设置动画。使用组动画,我能够制作动画:中心点、缩放和旋转。
博客和示例项目即将推出。
I should have read the documentation more carefully when it comes to transforms. Since transforms are dependent on a view's center point. I can't have simultaneous animations occurring modifying a transform and center, at the uiview level. Since the center is a dependency for a transform it has to be set immediately and then the rest of the animations can occur.
The solution was to animate at a view's layer. Using group animations I was able to animate: the center point, scaling and rotation.
Blog and sample project to come shortly.