I have a uiimageview and I want to move it while the animation of clock is running.The problem is when I press the button to move, the animation play the images and after the end of playing images, the image start to move 10px. It shouldn’t be like this and the animation and movement should start and end together.
-(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];
}
}
Hi you are doing a simple mistake please do both animation task and right going task in same animation one after other on the click of button…Use one animation block if if want it to happen at once two animation will animate at diffrent time.
define these macro and do task between start and stop animation