简体   繁体   中英

UIView frame origin x animation with bounce effect

I have managed to get my UIView to animate when moving its frame.origin.x from x to x-200; however, when frame.origin.x reaches x-200, I'd like it to bounce a little bit back and forth.

Anyone any tips as to how I should go about doing this? thanks

int targetX = 200;

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.1];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

myView.frame = CGRectMake(targetX, 0, [myView frame].size.width, [myView frame].size.height);
[UIView commitAnimations];

I believe that you'll need to do a path animation. See: http://www.bdunagan.com/2009/04/26/core-animation-on-the-iphone/ for a simple tutorial on doing that.

The basic animation just animates between one point and another with some velocity changes (ease-in, ease-out). Path animation can do curves, direction changes, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM