如何通过旋转正确设置子视图中心点的动画

发布于 2024-10-22 01:51:25 字数 1023 浏览 5 评论 0原文

我有两个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昇り龍 2024-10-29 01:51:25

当涉及到转换时,我应该更仔细地阅读文档。由于变换取决于视图的中心点。我无法在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文