IOS几种实现动画的方式

来源:互联网 发布:python 定时执行函数 编辑:程序博客网 时间:2024/06/03 01:58

1. 使用基本关键帧动画CABasicAnimation

特点:可做3D动画

详细介绍可参看两个帖子:
http://blog.csdn.net/iosevanhuang/article/details/14488239
http://blog.csdn.net/wscqqlucy/article/details/8669636

注:( CGAffineTransform CATransform3D 的比较 )
CGAffineTransform is used for 2-D manipulation of NSViews, UIViews, and other 2-D Core Graphics elements.
CATransform3D is a Core Animation structure that can do more complex 3-D manipulations of CALayers.( 搬运from stackOverFlow)

如:

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];    animation.fromValue = @(0);    animation.toValue = @(-M_PI);    animation.repeatCount = 0;    animation.duration = 0.4;    [aUIView.layer addAnimation:animation forKey:@"rotation"];    CATransform3D transform = CATransform3DIdentity;    transform.m34 = 1.0 / 500.0;    aUIView.layer.transform = transform;

2. 使用UIView关键帧动画animateKeyframesWithDuration

如:

[UIView animateKeyframesWithDuration:durationTime delay:0 options:0 animations:^{        [UIView addKeyframeWithRelativeStartTime:0*frameDuration relativeDuration:1*frameDuration animations:^{            weakSelf.pickGradeView.transform = CGAffineTransformMakeScale(0.01, 0.01);        }];        [UIView addKeyframeWithRelativeStartTime:1*frameDuration relativeDuration:1*frameDuration animations:^{            weakSelf.pickGradeView.alpha = 1.0;        }];    } completion:^(BOOL finished) {    }];

3.使用UIView animateWithDuration

如:

    __weak typeof(self) weakSelf = self;    [UIView animateWithDuration:1.0 delay:0.0 usingSpringWithDamping:1.0 initialSpringVelocity:0.5 options:0 animations:^{        __strong typeof(weakSelf) strongSelf = weakSelf;        strongSelf.shortNameLabel.transform = CGAffineTransformMakeScale(0.8, 0.8);    } completion:^(BOOL finished) {        [UIView animateWithDuration:0.4 delay:0.0 usingSpringWithDamping:0.5 initialSpringVelocity:0.5 options:0 animations:^{            __strong typeof(weakSelf) strongSelf = weakSelf;            strongSelf.shortNameLabel.transform = CGAffineTransformMakeScale(1.0, 1.0);        } completion:nil];    }];
0 0