Reputation: 109
I need the image to to up the screen like 15 units, slow down (not an immediate stop), then come back down. I am very new to this and dont know what to do. I hope someone can help. Let me know if you need more information. Thanks!
Upvotes: 0
Views: 1607
Reputation: 1542
You can use 2 path: CABasicAnimation or UIView animation (in code difference not great). UIView more simple and better for simple animation. CAAnimation needs in Quartz framework and also has more lower preferences. This two guides will help http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial , http://www.raywenderlich.com/5478/uiview-animation-tutorial-practical-recipes
Using CAAnimation simple (as example):
-(void)animationRotation
{
CABasicAnimation *anim;
anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; // this what you need - slow down (not an immediate stop)
anim.duration = 0.5;
anim.repeatCount = 1;
anim.fromValue = [NSNumber numberWithFloat:0];
[anim setDelegate:self];
anim.toValue = [NSNumber numberWithFloat:(15)];
[myView.layer addAnimation:anim forKey:@"transform"];
CGAffineTransform rot = CGAffineTransformMakeTranslation(15.0);
myView.transform = rot;
}
Upvotes: 4
Reputation: 80265
You take the UIImageView that contains the image and animate upwards with animateWithDuration:delay:options:animations:completion:
. In the animation block you just change the frame
of your image view.
In options
you use UIViewAnimationOptionCurveEaseOut
going up.
Once completed you immediately start a second animation this time using UIViewAnimationOptionCurveEaseIn
. Thus
NSTimeInterval durationUp = 1.5;
[UIView animateWithDuration:durationUp delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
CGRect f = imageView.frame;
f.origin.y += 15;
imageView.frame = f;
}
completion:nil];
[UIView animateWithDuration:1.5 delay:durationUp
options:UIViewAnimationOptionCurveEaseIn
animations:^{
CGRect f = imageView.frame;
f.origin.y -= 15;
imageView.frame = f;
}
completion:nil];
Upvotes: 1