0

我有一个uiimageview,我想在时钟动画运行时移动它。问题是当我按下按钮移动时,动画播放图像,播放图像结束后,图像开始移动10px。它不应该是这样的,动画和动作应该一起开始和结束。

-(IBAction) MoveRightButton : (id) sender {

 [self animateRight];
[self rightTimer];

}

-(IBAction) stopRight {

[image stopAnimating];
[rightTimer invalidate];

}

-(void) animateRight {

NSArray * moveRight = [[NSArray alloc] initWithObjects :
[uiimage imageNamed : @"Clock1.png"] , .... , nil];

UIImage *defaultImage = [UIImage imageNamed : @"Clock1.png"];
[image setImage : defaultFace];
image.animationImages = moveRight;

image.animationDuration = 0.5;
image.animationRepeatCount = 1;
[image startAnimating];
}

-(void) goRight {
[UIView animateWithDuration : 0.5 animation : ^{
image.frame = CGRectMake (image.frame.origin.x + 10, image.frame.origin.y,image.frame.size.width, image.frame.size.height);
}];
[self stopRight];
}

-(void) rightTimer {
rightTimer = [NSTimer scheduledTimerWithTimeInterval : 0.5 
target : self  
selector : @selector(goRight) 
userInfo : nil  
repeats : YES];

if (rightTimer == nil) {
rightTimer = [NSTimer scheduledTimerWithTimeInterval : 0.5 
target : self  
selector : @selector(goRight) 
userInfo : nil  
repeats : YES];
 }
}
4

1 回答 1

0

嗨,您犯了一个简单的错误,请在单击按钮时依次在同一动画中执行动画任务和右行任务...如果希望它同时发生,请使用一个动画块,两个动画将在不同时间进行动画处理。

#define StartAnimation(duration)                  [UIView beginAnimations:nil context:NULL];[UIView setAnimationDuration:duration];[UIView setAnimationRepeatAutoreverses:NO];[UIView setAnimationRepeatCount:0]

#define StopAnimation                   [UIView commitAnimations]

定义这些宏并在开始和停止动画之间执行任务

于 2013-01-07T15:06:04.543 回答