我有一个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];
}
}
答案 0 :(得分:0)
嗨,你正在做一个简单的错误,请点击按钮一个接一个地在同一个动画中做动画任务和正确的任务...使用一个动画块,如果它想要立即发生两个动画将动画不同的时间。
#define StartAnimation(duration) [UIView beginAnimations:nil context:NULL];[UIView setAnimationDuration:duration];[UIView setAnimationRepeatAutoreverses:NO];[UIView setAnimationRepeatCount:0]
#define StopAnimation [UIView commitAnimations]
定义这些宏并在开始和停止动画之间执行任务