图片浏览(CATransition)转场动画
Main.storyboard

ViewController.m
//
// ViewController.m
// 8A04.图片浏览(转场动画)
//
// Created by huan on 16/2/4.
// Copyright © 2016年 huanxi. All rights reserved.
//
#import "ViewController.h"
#define AnimationDuration 2
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
-(IBAction)tapView:(UITapGestureRecognizer *)sender;
@property (nonatomic, strong) NSMutableArray *imgs;
@property (nonatomic, assign) NSInteger currentImgIndex;//当前的索引
@end
@implementation ViewController
-(NSMutableArray *)imgs{
if (!_imgs) {
_imgs = [NSMutableArray array];
for (NSInteger i = 1; i < 10; i++) {
NSString *imgName = [NSString stringWithFormat:@"%ld",i];
[_imgs addObject:imgName];
}
}
return _imgs;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(@"%@",self.imgs);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)tapView:(UITapGestureRecognizer *)tap{
//实现判断图片的左半边还是右半边
//获取触摸点
CGPoint point = [tap locationInView:tap.view];
NSLog(@"%@", NSStringFromCGPoint(point));
if (point.x <= tap.view.bounds.size.width *0.5) {
NSLog(@"上一张");
[self previous];
}else{
NSLog(@"下一张");
[self next];
}
}
-(void)previous{
//判断当前图片是不是第一张
if (self.currentImgIndex == 0) {
return;
}
//减索引 改图片
self.currentImgIndex --;
self.imageView.image = [UIImage imageNamed:self.imgs[self.currentImgIndex]];
//转场动画
CATransition *animation = [CATransition animation];
animation.type = @"push";
//默认就是fromLeft
animation.subtype = @"fromLeft";
animation.duration = AnimationDuration;
[self.imageView.layer addAnimation:animation forKey:nil];
}
/**
* 提示:转场动画的类型(type)和子类型(subtype)能用字符串常量就用字符串常量
*/
/**
*******************************************************
type:动画类型(比如:滴水效果,翻转效果...)
-------------------------------------------------------
fade kCATransitionFade 交叉淡化过渡
moveIn kCATransitionMoveIn 新视图移到旧视图上面
push kCATransitionPush 新视图把旧视图推出去
reveal kCATransitionReveal 将旧视图移开,显示下面的新视图
pageCurl 向上翻一页
pageUnCurl 向下翻一页
rippleEffect 滴水效果
suckEffect 收缩效果,如一块布被抽走
cube 立方体效果
oglFlip 上下左右翻转效果
rotate 旋转效果
cameraIrisHollowClose 相机镜头关上效果(不支持过渡方向)
cameraIrisHollowOpen 相机镜头打开效果(不支持过渡方向)
*******************************************************
subtype: 动画方向(比如说是从左边进入,还是从右边进入...)
------------------------------------------------------
kCATransitionFromRight;
kCATransitionFromLeft;
kCATransitionFromTop;
kCATransitionFromBottom;
当 type 为@"rotate"(旋转)的时候,它也有几个对应的 subtype,分别为:
90cw 逆时针旋转 90°
90ccw 顺时针旋转 90°
180cw 逆时针旋转 180°
180ccw 顺时针旋转 180°
**/
-(void)next{
//判断当前图片是不是最好一张
if(self.currentImgIndex == self.imgs.count - 1){
NSLog(@"已经是最好一张");
return;
}
//加索引 改图片
self.currentImgIndex ++;
self.imageView.image = [UIImage imageNamed:self.imgs[self.currentImgIndex]];
//设置图片的时候,使用转场动画
CATransition *animation = [CATransition animation];
//设置转场动画的类型
// `fade', `moveIn', `push' and `reveal'.
//fade 渐变 moveIn 直接移动
animation.type = @"rotate";
// animation.type = kCATransitionPush;
//设置转场动画的子类型
// `fromLeft', `fromRight', `fromTop' and
// * `fromBottom' fromLeft 从左边开始推
animation.subtype = @"90cw";
animation.duration = AnimationDuration;
[self.imageView.layer addAnimation:animation forKey:nil];
}
@end
图片浏览(CATransition)转场动画的更多相关文章
- CATransition转场动画
背景: 最近在温习动画,分享个简单系统的转场动画 viewcontroller *VC=[self.storyboard instantiateViewControllerWithIdentifier ...
- core Animation之CATransition(转场动画)
用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果.iOS比Mac OS X的转场动画效果少一点 UINavigationController就是通过CATransition实现了将控制器的视图 ...
- 之四:CATransition - 转场动画
关键属性: type 过渡效果 kCATransitionFade 淡出 kCATransitionMoveIn 覆盖原图 kCATransitionPush 推出 kCATransition ...
- CATransition 转场动画解析
http://blog.csdn.net/mad2man/article/details/17260901
- iOS 转场动画核心内容
CATransition——转场动画 CATransition是CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果.iOS比Mac OS X的转场动画效果少一点. ...
- iOS:核心动画之转场动画CATransition
转场动画——CATransition CATransition是CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果.iOS比Mac OS X的转场动画效果少一点 U ...
- ios手势复习值之换图片-转场动画(纯代码)
目标:实现通过手势进行图片的切换 通过左扫右扫 来实现(纯代码) 添加三个属性 1uiImageView 用来显示图片的view 2 index 用来表示图片的索引 3 ISLeft 判断是不是向 ...
- iOS CATransition 自定义转场动画
https://www.jianshu.com/p/39c051cfe7dd CATransition CATransition 是CAAnimation的子类(如下图所示),用于控制器和控制器之间的 ...
- CATransition自定义转场动画
我们可以通过CATransiton来自定义一些漂亮的转场动画, CATransition继承自CAAnimation, 所以用法跟CAAnimation差不多 先直接上一个代码: #import &q ...
随机推荐
- Math Start!
(1)Add Digits 解题思路: 基于同余的数学属性. 数字的根(即题目所要求返回的最终结果)与该数字除以9时的余数相同(并且该余数将始终为单个数字). take 438 as an examp ...
- mysql分表和表分区详解
为什么要分表和分区? 日常开发中我们经常会遇到大表的情况,所谓的大表是指存储了百万级乃至千万级条记录的表.这样的表过于庞大,导致数据库在查询和插入的时候耗时太长,性能低下,如果涉及联合查询的情况,性能 ...
- linux命令(3):pwd命令
Linux中用 pwd 命令来查看”当前工作目录“的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置. ...
- 直接用<img> 的src属性显示base64转码后的字符串成图片
直接用<img> 的src属性显示base64转码后的字符串成图片 <img src="base64转码后的字符串" ></img> 下面的图片 ...
- 通过pinyin4j.jar将(汉字拼音混合字符串)转化成字母首字母
通过pinyin4j.jar将(汉字拼音混合字符串)转化成字母首字母 例如 我的中国心 ==> wdzgx 我的中国心ya ==> wdzgxya woai我的中国 ==> w ...
- poj 2594 Treasure Exploration (二分匹配)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 6558 Accepted: 2 ...
- alphaRGB 转 RGB、16位
struct xColor { BYTE b, g, r, a; }; struct RGBColor { BYTE b, g, r; }; //void operator <<(RGBC ...
- Hibernate 注解的用法以及说明
1.类级别注解 @Entity 映射实体类 @Table 映射数句库表 @Entity(name="tableName") - 必须,注解将一个类声明为一个实体be ...
- [刘阳Java]_斗胆介绍一下Eclipse快捷键大全[超详细]_第6讲
斗胆让我在这里介绍一下Eclipse快捷键有哪些 ctrl+shirt+r 打开资源 这组快捷键可以让你开打Eclipse工作区中任何一个文件,你只需要输入你想查找的文件名字即可,而且绝对支持模糊检索 ...
- ABAP POPUP函数
POPUP_TO_CONFIRM_LOSS_OF_DATA 弹出一个对话框告知用户有可能丢失数据,询问是否操作继续.POPUP_TO_CONFIRM_STEP 弹出一个对话框询问用户是否操作继续. P ...