- (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...
}
) 내가 레이블을 회전
가, 지금은 그것을 취소 할 회전, 나는 사이트의 가능성이 질문을 검색하고, 약 2 솔루션을 발견 , 시도했지만 두 솔루션이 작동하지 않습니다.
btnPressed
에 또한 다시 같은 각도로 회전 할 수 있습니다. 예 : +180을 돌린 다음 -180으로 다시 돌리십시오. : P – HDdeveloper