- (void)viewDidLoad
{
[super viewDidLoad];
label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 100, 50)];
label.layer.cornerRadius = 5.0f;
label.text = @"hello world";
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
[label release];
[self startAnimation];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(0, 0, 60, 30);
[btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
- (void)startAnimation
{
CGAffineTransform transForm = CGAffineTransformMakeRotation(angel * M_PI/180.0f);
[UIView animateWithDuration:0.1f delay:0.0f options:UIViewAnimationOptionCurveLinear animations:^(void){
label.transform = transForm;
} completion:^(BOOL finished) {
NSLog(@"1");
angel = angel + 5;
[self startAnimation];
}];
}
- (void)btnPressed:(id)sender
{
//method 1 :[label.layer removeAllAnimations]; not work...
//method 2 : CGAffineTransform transForm = CGAffineTransformMakeRotation(M_PI/180.0f);
//label.transform = transForm; not work...
}
)
我旋轉的標籤,現在我想取消它,我搜索的網站可能的問題,並發現了大約兩個解決方案,我試過了,但是這兩個解決方案不起作用。
您還可以旋轉回相同的角度。例如:如果你旋轉180度,然後再旋轉-180 ..:P – HDdeveloper