2013-01-07 116 views
0

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

-(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

嗨,你在做一个简单的错误,请两者都做动画的任务,右正在进行的任务在同一个动画上的其他按钮,点击后...如果,如果希望它发生在一次两个用一个动画块动画将在不同的时间生成动画。

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

#define StopAnimation     [UIView commitAnimations] 

定义这些宏观和起点之间做任务和停止动画

+0

索里。你的意思是: - (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 animateRight]; }]; [self stopRight]; }是吗? –

+0

应该工作尝试 – amar

+0

,你可以说我怎么能移动我的uiimageview,而我一直在按uibutton?旧的代码就像你必须按2或3次再次移动和长按无法正常工作,因为它是触摸 –