iOS3D转场动画
2015-07-11 13:55
363 查看
//3D转场动画的实现方法
// ViewController.m
// 3DAnimation
//
// Created by Apple-YangWei on 15/5/12.
// Copyright (c) 2015年 Apple-YangWei. All rights reserved.
//
#import "ViewController.h"
@interface
ViewController ()
@property (weak,
nonatomic) IBOutlet
UIImageView *imageView;
@property(nonatomic,assign)
int index;//记录图片的顺序
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
self.index =
1;
UIImageView *imageView = [[UIImageView
alloc] initWithFrame:CGRectMake(43,
39, 235,
394)];
//imageView.image = [UIImage imageNamed:@"1.JPG"];
//点击上一张
UIButton *previousButton = [[UIButton
alloc] initWithFrame:CGRectMake(self.imageView.center.x-150,
self.imageView.bounds.size.height+50,
88, 40)];
previousButton.backgroundColor = [UIColor
grayColor];
[previousButton setTitle:@"previous"
forState:UIControlStateNormal];
[previousButton addTarget:self
action:@selector(previousPicture)
forControlEvents:UIControlEventTouchUpInside];
//点击下一张
UIButton *nextButton = [[UIButton
alloc] initWithFrame:CGRectMake(self.imageView.center.x+50,
self.imageView.bounds.size.height+50,
88, 40)];
nextButton.backgroundColor = [UIColor
grayColor];
[nextButton setTitle:@"next"
forState:UIControlStateNormal];
[nextButton addTarget:self
action:@selector(nextPicture)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:previousButton];
[self.view addSubview:nextButton];
[self.view addSubview:imageView];
}
-(void)previousPicture{
self.index--;
if (self.index <
1) {
self.index = 7;
}
[self animateWith:kCATransitionFromLeft];
}
-(void)nextPicture{
self.index++;
if(self.index >
7){
self.index = 1;
}
[self animateWith:kCATransitionFromRight];
}
//获取picture,并创建动画
-(void)animateWith: (NSString *) direction{
NSString *imageName = [NSString stringWithFormat:@"%d.JPG",
self.index];
UIImage *newImage = [UIImage imageNamed:imageName];
self.imageView.image = newImage;
// 1.创建核心动画
CATransition *ca = [CATransition animation];
//动画过度类型
ca.type =
@"cube";
//动画过度方向
ca.subtype = direction;
//动画时间
ca.duration =
1;
//添加到图层
[self.imageView.layer addAnimation:ca forKey:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
// ViewController.m
// 3DAnimation
//
// Created by Apple-YangWei on 15/5/12.
// Copyright (c) 2015年 Apple-YangWei. All rights reserved.
//
#import "ViewController.h"
@interface
ViewController ()
@property (weak,
nonatomic) IBOutlet
UIImageView *imageView;
@property(nonatomic,assign)
int index;//记录图片的顺序
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
self.index =
1;
UIImageView *imageView = [[UIImageView
alloc] initWithFrame:CGRectMake(43,
39, 235,
394)];
//imageView.image = [UIImage imageNamed:@"1.JPG"];
//点击上一张
UIButton *previousButton = [[UIButton
alloc] initWithFrame:CGRectMake(self.imageView.center.x-150,
self.imageView.bounds.size.height+50,
88, 40)];
previousButton.backgroundColor = [UIColor
grayColor];
[previousButton setTitle:@"previous"
forState:UIControlStateNormal];
[previousButton addTarget:self
action:@selector(previousPicture)
forControlEvents:UIControlEventTouchUpInside];
//点击下一张
UIButton *nextButton = [[UIButton
alloc] initWithFrame:CGRectMake(self.imageView.center.x+50,
self.imageView.bounds.size.height+50,
88, 40)];
nextButton.backgroundColor = [UIColor
grayColor];
[nextButton setTitle:@"next"
forState:UIControlStateNormal];
[nextButton addTarget:self
action:@selector(nextPicture)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:previousButton];
[self.view addSubview:nextButton];
[self.view addSubview:imageView];
}
-(void)previousPicture{
self.index--;
if (self.index <
1) {
self.index = 7;
}
[self animateWith:kCATransitionFromLeft];
}
-(void)nextPicture{
self.index++;
if(self.index >
7){
self.index = 1;
}
[self animateWith:kCATransitionFromRight];
}
//获取picture,并创建动画
-(void)animateWith: (NSString *) direction{
NSString *imageName = [NSString stringWithFormat:@"%d.JPG",
self.index];
UIImage *newImage = [UIImage imageNamed:imageName];
self.imageView.image = newImage;
// 1.创建核心动画
CATransition *ca = [CATransition animation];
//动画过度类型
ca.type =
@"cube";
//动画过度方向
ca.subtype = direction;
//动画时间
ca.duration =
1;
//添加到图层
[self.imageView.layer addAnimation:ca forKey:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- iOS开发雷达动画效果实现
- ios开发 预处理.pch文件
- iOS--NSDictionary
- iOS字典转模型方法代理片段
- IOS WebView中JS和OC相互调用
- iOSpush过后返回多级界面
- IOS 给Button设置一个简单的动画
- iOS常见警告解决
- iOS 8 Xcode6 设置Launch Image 启动图片
- 关于友盟社会化分享框架的一些使用心得
- 分享一些ios干货
- IOS xib 和storyboard的区别
- IOS 多线程 RUNLOOP 机制 (二)
- IOS 多线程 RUNLOOP 机制 (一)
- iOS在当前视图中推出另外一个背景透明的视图控制器
- 修复iOS7下leftBarButtonItem位置相比之前版本靠右的问题
- ios崩溃日志1
- iOS基础(c)-内存管理
- iOS开发,#define的使用
- iOS 9公测开启 智能预测/省电模式亮相