我想从 UIImageView
扩展一个类,它将无限旋转宇宙图像。所以我可以简单地将这个 ImageView 作为其他 UI 元素的背景 View 。
这里有 3 个问题:
- 从
UIImageview
类扩展的方式是否正确。 - 如何保持无限旋转,并且作为背景,当把它放到其他 View 中时,我不需要写额外的代码行。
- 我写了一个粗略的原型(prototype),当我把它放到其他 View 中作为背景时,这个 View 中的所有 UI 元素都随着图像旋转。
最佳答案
假设您有一个 UIImageView 并在其上分配一个图像并命名为 myImgView。在 viewDidLoad 上,添加如下代码:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationRepeatCount:MAXFLOAT];
myImgView.transform = CGAffineTransformMakeRotation(M_PI);
[UIView commitAnimations];
它对我来说就像一种魅力。
关于iphone - 无限旋转图片背景UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9715967/