旋转根本停不下来,
UIView 的旋转可以看我的博客 iOS大典之点击旋转,
这里举例一个常用的 UILabel, 将字体像钟表一样停不下了
1 . 创建一个UILabel 作为实例变量和属性
@property (strong, nonatomic) UILabel *label;
2 . 在viewDidLoad方法中添加
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGRect bounds = self.view.bounds;
CGRect labelFrame = CGRectMake(bounds.origin.x, CGRectGetMidY(bounds) - 50, bounds.size.width, 100);
self.label = [[UILabel alloc] initWithFrame:labelFrame];
self.label.font = [UIFont fontWithName:@"Helvatica" size:70];
self.label.text = @"阿里咕噜就呦黑!";
self.label.textAlignment = NSTextAlignmentCenter;
self.label.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.label];
[self rotateLabelDown];
}
3 . 设置动画, 定义方法, 一个旋转下去 , 一个旋转上来
- (void)rotateLabelDown
{
[UIView animateWithDuration:0.5 animations:^{
self.label.transform = CGAffineTransformMakeRotation(M_PI);
} completion:^(BOOL finished) {
[self rotateLabelUp];
}];
}
- (void)rotateLabelUp
{
[UIView animateWithDuration:0.5 animations:^{
self.label.transform = CGAffineTransformMakeRotation(0);
} completion:^(BOOL finished) {
[self rotateLabelDown];
}];
}
记得要调用方法
[self rotateLabelDown];
over