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];
}
}
索裏。你的意思是: - (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]; }是嗎? –
應該工作嘗試 – amar
,你可以說我怎麼能移動我的uiimageview,而我一直在按uibutton?舊的代碼就像你必須按2或3次再次移動和長按無法正常工作,因爲它是觸摸 –