连续动画

来源:互联网 发布:jquery.qrcode.js 编辑:程序博客网 时间:2024/04/30 08:27
在一个动画block中,让一个button移动两次,而且设置了setAnimationDuration:3

但是表现出来的效果是,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];
}

原创粉丝点击