我想在一个动画block中,让一个button移动两次,而且设置了setAnimationDuration:3
但是表现出来的效果是,button直接移动到第一个位置,然后用了3秒的时间,移动到了第二个位置请问是什么原因阿?? [UIView beginAnimations:@"move button2" context:nil];
[UIView setAnimationDuration:5]; button1.frame = CGRectMake(100, 0, 100, 100);
button1.frame = CGRectMake(100, 100, 100, 100); [UIView commitAnimations];
但是表现出来的效果是,button直接移动到第一个位置,然后用了3秒的时间,移动到了第二个位置请问是什么原因阿?? [UIView beginAnimations:@"move button2" context:nil];
[UIView setAnimationDuration:5]; button1.frame = CGRectMake(100, 0, 100, 100);
button1.frame = CGRectMake(100, 100, 100, 100); [UIView commitAnimations];
你设置两次frame, 系统是不知道每次绘制动画多少时间的,所以展示的可能和你想的不一样;你应该每次设置frame用一个动画效果,你要的就有了。
self = [super init];
if (self != nil) {
[self.view setBackgroundColor:[UIColor greenColor]];
button1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, 20, 50)];
[self.view addSubview:button1];
button1.backgroundColor = [UIColor redColor];
button1.hidden = NO;
[UIView beginAnimations:@"move button" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animation2:)];
[UIView setAnimationDuration:2];
button1.frame = CGRectMake(100, 0, 100, 100);
// button1.frame = CGRectMake(100, 100, 100, 100);
//button1.frame = CGRectMake(200, 100, 100, 100);
[UIView commitAnimations];
}
return self;
}-(void)animation2:(id)sender{
[UIView beginAnimations:@"move button" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animation3:)];
[UIView setAnimationDuration:2];
button1.frame = CGRectMake(100, 100, 100, 100);
//button1.frame = CGRectMake(200, 100, 100, 100);
[UIView commitAnimations];
}-(void)animation3:(id)sender{
[UIView beginAnimations:@"move button" context:nil];
[UIView setAnimationDuration:2];
button1.frame = CGRectMake(200, 100, 100, 100);
[UIView commitAnimations];
}