您的位置:首页 > 移动开发 > IOS开发

IOS几种实现动画的方式

2015-07-22 21:10 507 查看
1. 使用基本关键帧动画CABasicAnimation

特点:可做3D动画

详细介绍可参看两个帖子:

http://blog.csdn.net/iosevanhuang/article/details/14488239

/article/7693388.html

注:( 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];

}];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: