UIView 动画

1. 代码块方式实现动画;

2. begin/commit 方式实现nest 的动画;


一、代码块方式实现:

需要用到这几个API

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL

/* Performs `animations` using a timing curve described by the motion of a spring. When `dampingRatio` is 1, the animation will smoothly decelerate to its final model values without oscillating. Damping ratios less than 1 will oscillate more and more before coming to a complete stop. You can use the initial spring velocity to specify how fast the object at the end of the simulated spring was moving before it was attached. It's a unit coordinate system, where 1 is defined as travelling the total animation distance in a second. So if you're changing an object's position by 200pt in this animation, and you want the animation to behave as if the object was moving at 100pt/s before the animation started, you'd pass 0.5. You'll typically want to pass 0 for the velocity. */ 
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);

example:

[UIView animateWithDuration:1
                         animations:^(void){
                             airship.alpha = 1.0;
                             airship.transform = CGAffineTransformMakeTranslation(0, 20);
                         }
                         completion:^(BOOL finished){

                         }];

二、begin/commit 方式实现 nest 动画;

当我们需要同时实现一个UIView的缩放、位置、不透明度等属性的同时动画时,需要用到这种方法。

+ (void)beginAnimations:(NSString *)animationID context:(void *)context;  // additional context info passed to will start/did stop selectors. begin/commit can be nested
+ (void)commitAnimations;                                                 // starts up any animations when the top level animation is commited

example :

                         [UIView beginAnimations:@"animation" context:nil];
                         [UIView setAnimationDidStopSelector:@selector(animationDidStop)];
                         [UIView setAnimationDuration:1];
                         [UIView setAnimationDelegate:self];
                         airship.alpha = 0.0;
                         CGRect rect = airship.bounds;
                         airship.bounds = CGRectMake(0, 0, rect.size.width/2.0, rect.size.height/2.0);
                         CGPoint center = airship.center;
                         airship.center = CGPointMake(center.x, 0);
                         [UIView commitAnimations];












  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值