我想创建一个同时移动和旋转 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/