iphone - 动画移动和旋转 UIView 不太有效

标签 iphone ipad ios uiview cgaffinetransform

我想创建一个同时移动和旋转 UIView 的动画。我尝试了以下代码:

[UIView beginAnimations:@"MoveAndRotateAnimation" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDuration:kAnimationDuration];

myView.frame = newFrame;
myView.transform = CGAffineTransformMakeRotation(0.4);

[UIView commitAnimations];

结果是,动画结束后, View 绘制不正确(某些部分不再可见)。如果我只更改动画的帧或变换, View 将正确绘制。仅当我同时设置框架和转换时才会出现此问题。

同时为 View 的移动和旋转设置动画的正确方法是什么?

最佳答案

如果您还对旋转等内容进行动画处理,则不能使用 frame、bounds 或 center。您需要对所有内容使用 CGAffineTransforms 并将它们连接在一起。像这样:

CGAffineTransform transform = CGAffineTransformMakeTranslation(100,100);
transform = CGAffineTransformRotate(transform, 0.4);

[UIView beginAnimations:@"MoveAndRotateAnimation" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDuration:kAnimationDuration];

myView.transform = transform;

[UIView commitAnimations];

关于iphone - 动画移动和旋转 UIView 不太有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4380747/

相关文章:

Iphone:如何在当前日期上添加年份并将其以 2011-11-20 格式的字符串返回

javascript - socket.io - iPad 总是超时,尽管它已连接

ios - 带有 "Prefers Large Titles"和嵌入式 PageViewController 的导航栏不折叠

ios - Swift - 时区关闭一小时/秒 FromGMT 不正确

ios - 未调用 BLE 外设委托(delegate)

ios - Google Map Direction API 返回零结果 Swift

mysql - 如何正确缓存/更新使用远程数据库的数据驱动 iPhone 应用程序?

iphone - 调整大小后提高图像质量

iphone - 如何在 iPhone 应用程序中本地化 bundle 显示名称?

ASP.NET View 状态使 iPad 浏览器崩溃