本文主要是介绍动画(三)(转场动画, 动画组),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
代码如下:
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *iconImage;
- (IBAction)previous;
- (IBAction)nextBtn;
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)previous {
self.index --;
if (self.index == -1) {
self.index = 11;
}
NSString *imageString = [NSString stringWithFormat:@"%d.jpg", self.index +1];
self.iconImage.image = [UIImage imageNamed:imageString];
CATransition *transitionAnimation = [CATransition animation];
transitionAnimation.duration = 1;
transitionAnimation.startProgress = 0.8;
/**
*最关键就是----。》》》transitionAnimation.type
*/
transitionAnimation.type = @"pageCurl";
transitionAnimation.subtype = kCATransitionFromLeft;
[self.iconImage.layer addAnimation:transitionAnimation forKey:nil];
}
- (IBAction)nextBtn {
self.index ++;
if (self.index == 12) {
self.index = 0;
}
NSString *imageString = [NSString stringWithFormat:@"%d.jpg", self.index +1];
self.iconImage.image = [UIImage imageNamed:imageString];
CATransition *transitionAnimation = [CATransition animation];
transitionAnimation.duration = 1;
transitionAnimation.startProgress = 0.8;
/**
*最关键就是----。》》》transitionAnimation.type
*改变动画属性用来做动画效果
*/
transitionAnimation.type = @"pageCurl";
transitionAnimation.subtype = kCATransitionFromRight;
[self.iconImage.layer addAnimation:transitionAnimation forKey:nil];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
// 1.创建旋转动画对象
CABasicAnimation *rotate = [CABasicAnimation animation];
rotate.keyPath = @"transform.rotation";
rotate.toValue = @(M_PI);
// 2.创建缩放动画对象
CABasicAnimation *scale = [CABasicAnimation animation];
scale.keyPath = @"transform.scale";
scale.toValue = @(0.0);
// 3.平移动画
CABasicAnimation *move = [CABasicAnimation animation];
move.keyPath = @"transform.translation";
move.toValue = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
// 4.将所有的动画添加到动画组中
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = @[rotate, scale, move];
group.duration = 2.0;
group.removedOnCompletion = NO;
group.fillMode = kCAFillModeForwards;
[self.myImageView.layer addAnimation:group forKey:nil];}
@end
这篇关于动画(三)(转场动画, 动画组)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!