Cabasicanimation Rotate Returns to Original Position

CABasicAnimation back to its original position after it finish it's 1 cycle

Have you tried this?

moveAnimation.fillMode = kCAFillModeForwards;
moveAnimation.removedOnCompletion = NO;

EDIT
As far as I can see you can also use animateWithDuration which has a completion block.
Example would be:

CGRect rect = btnSpecialForListing.titleLabel.frame;
[UIView animateWithDuration:2.0 animations:^{

rect.origin.y = -7;
btnSpecialForListing.titleLabel.frame = rect;

} completion:^(BOOL finished){

[UIView animateWithDuration:3.5 animation:^{
rect.origin.x = -400;
btnSpecialForListing.titleLabel.frame = rect;
}];

}];

After rotating a CALayer using CABasicAnimation the layer jumps back to it's unrotated position

Have you set the removedOnCompletion property of the rotation animation to NO, e.g.,

rota.removedOnCompletion = NO;

That should leave the presentation layer where it was when the animation finished. The default is YES, which will snap back to the model value, i.e., the behavior you describe.

The fillMode should also be set, i.e.,

rota.fillMode = kCAFillModeForwards;

iOS animating object goes back to original position

add following lines before adding animation

animation.isRemovedOnCompletion = false
animation.fillMode = kCAFillModeForwards

Swift

animation.fillMode = .forwards
animation.isRemovedOnCompletion = false

Using CABasicAnimation to rotate a UIImageView more than once

pass incremental value of angle see my code

static int imgAngle=0;
- (void)doAnimation
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.duration = 5;
animation.additive = YES;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.fromValue = [NSNumber numberWithFloat:DEGREES_TO_RADIANS(imgAngle)];
animation.toValue = [NSNumber numberWithFloat:DEGREES_TO_RADIANS(imgAngle+90)];
[self.imgView.layer addAnimation:animation forKey:@"90rotation"];

imgAngle+=90;
if (imgAngle>360) {
imgAngle = 0;
}
}

Above code is just for idea. Its not tested



Related Topics



Leave a reply



Submit