但是表现出来的效果是,button直接移动到第一个位置,然后用了3秒的时间,移动到了第二个位置
- (id)init{
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];
}