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)转场动画的更多相关文章

  1. CATransition转场动画

    背景: 最近在温习动画,分享个简单系统的转场动画 viewcontroller *VC=[self.storyboard instantiateViewControllerWithIdentifier ...

  2. core Animation之CATransition(转场动画)

    用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果.iOS比Mac OS X的转场动画效果少一点 UINavigationController就是通过CATransition实现了将控制器的视图 ...

  3. 之四:CATransition - 转场动画

    关键属性: type 过渡效果  kCATransitionFade  淡出 kCATransitionMoveIn  覆盖原图 kCATransitionPush  推出 kCATransition ...

  4. CATransition 转场动画解析

    http://blog.csdn.net/mad2man/article/details/17260901

  5. iOS 转场动画核心内容

    CATransition——转场动画 CATransition是CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果.iOS比Mac OS X的转场动画效果少一点. ...

  6. iOS:核心动画之转场动画CATransition

    转场动画——CATransition CATransition是CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果.iOS比Mac OS X的转场动画效果少一点 U ...

  7. ios手势复习值之换图片-转场动画(纯代码)

    目标:实现通过手势进行图片的切换   通过左扫右扫 来实现(纯代码) 添加三个属性 1uiImageView 用来显示图片的view 2 index 用来表示图片的索引 3 ISLeft 判断是不是向 ...

  8. iOS CATransition 自定义转场动画

    https://www.jianshu.com/p/39c051cfe7dd CATransition CATransition 是CAAnimation的子类(如下图所示),用于控制器和控制器之间的 ...

  9. CATransition自定义转场动画

    我们可以通过CATransiton来自定义一些漂亮的转场动画, CATransition继承自CAAnimation, 所以用法跟CAAnimation差不多 先直接上一个代码: #import &q ...

随机推荐

  1. 【css3】浏览器内核及其兼容性

    浏览器内核分类如下: 1.Webkit内核: 使用此引擎内核的浏览器有:Safari(包括移动版和桌面版).Chrome.其私有属性的前缀是-webkit-. 2.Gecko内核: 使用此引擎内核的浏 ...

  2. python时间函数学习

    格式化当前日期: import time print time.strftime('%Y-%m-%d') 获取一天前的日期: import datetime import time onedayago ...

  3. debug命令简介

    debug命令不区分大小,debug的命令都是一个字母,后跟或不跟参数 1.debug [路径\文件] [参数] [参数]--[参数] debug相应程序 2. D(Dump) [地址] [范围] 显 ...

  4. mysql 行转列 和 列转行

    我们有时会将一些数据已逗号的连接方式存在数据库,当取出时我们又想单独一个个取出来 利用help_topic 的自增性 LENGTH(wu.`password`) - length(replace(wu ...

  5. python之 list、tuple、dict、set

    2016-08-24   14:32:59 list Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. 例如:定义一个列表L,里面存放了一些姓氏 ...

  6. LSD-SLAM深入学习(4)-非ROS改造

    前言 没错,距离上一次博客的发布已经俩月了,今天是圣诞节,圣诞快乐. 在前几篇中已经完成了ROS下面的一系列操作.如有任何问题,feel free to contact me at robotsmin ...

  7. MyEclipse +Flex 整合

         最近想利用red5开发一个流媒体的程序,在网上找了半天没有一个可用的代码,要么是下载需要多少币,要么是没有.纠结了半天,最后决定自检看着文字版本的教程,自己编写一个.         看着一 ...

  8. css3的背景颜色渐变@线性渐变

    背景颜色渐变之线性渐变 语法形式: firefox浏览器 background:-moz-linear-gradient(position/deg,startColor,endColor); oper ...

  9. [转]学术型 github 畅想

    转自 http://wulfric.me/2013/09/github-and-academy/ 以 github 的精神提供学术服务,也许是一个不错的方向. 什么是 github? Github 是 ...

  10. 百度UEditor基本使用

    1 首先奉上链接其http://ueditor.baidu.com/website/index.html 更多更详细内容在其官方api上,本文只是一个归类总结性文章. 2 下载链接http://ued ...