(
- (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...
}
)
我旋转标签,现在我想取消它,我在网站上搜索了可能的问题,发现了两个解决方案,我尝试了,但这两个解决方案都不起作用..