(素材源码)猫猫学iOS(四十一)UI之核心动画 两行代码搞定3D转场(做android的哭死)
猫猫分享,必须精品
原创文章,欢迎转载。转载请注明:翟乃玉的博客
地址:http://blog.csdn.net/u013357243?viewmode=contents
源码素材地址:http://download.csdn.net/detail/u013357243/8677065
效果:
代码:
#import "NYViewController.h"
@interface NYViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
- (IBAction)nextBtnClick:(id)sender;
- (IBAction)preBtnClick:(id)sender;
@property (nonatomic, assign) int index;
@end
@implementation NYViewController
// 下一张
- (IBAction)nextBtnClick:(id)sender {
self.index++;
if (self.index >7) {
self.index = 1;
}
NSString *imageName = [NSString stringWithFormat:@"%d.jpg", self.index];
UIImage *newImage = [UIImage imageNamed:imageName];
self.iconView.image = newImage;
// 1.创建核心动画
CATransition *ca = [CATransition animation];
// 1.1动画过渡类型
ca.type = @"cube";
// 1.2动画过渡方向
ca.subtype = kCATransitionFromRight;
// 1.3动画起点(在整体动画的百分比)
//ca.startProgress = 0.5;
//1.3动画终点(在整体动画的百分比)
//ca.endProgress = 0.5;
// 动画时间
ca.duration = 1;
// 2.添加核心动画
[self.iconView.layer addAnimation:ca forKey:nil];
}
// 上一张
- (IBAction)preBtnClick:(id)sender {
self.index--;
if (self.index < 1) {
self.index = 7;
}
NSString *imageName = [NSString stringWithFormat:@"%d.jpg", self.index];
UIImage *newImage = [UIImage imageNamed:imageName];
self.iconView.image = newImage;
// 1.创建核心动画
CATransition *ca = [CATransition animation];
// 1.1告诉系统执行什么动画
ca.type = @"cube";
ca.subtype = kCATransitionFromLeft;
ca.duration = 1;
// 2.添加核心动画
[self.iconView.layer addAnimation:ca forKey:nil];
}
@end