图片浏览(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 ...
随机推荐
- Android菜鸟成长记7 -- Android的五大布局
Android五大布局,相信android的都了解过,今天我根据自己的学习整理一下五大布局,主要介绍的是线性布局(LiearLayout),因为,其他的布局使用率不是很高. Android的五大布局 ...
- Python常用模块学习
1.模块介绍 2.time & datetime模块 3.random 4.os 5.sys 6.shutil 7.json&pickle 8.shelve 9.xml处理 10.ya ...
- 转载:Solr的自动完成实现方式(第三部分:Suggester方式续)
转自:http://www.cnblogs.com/ibook360/archive/2011/11/30/2269126.html 在之前的两个部分(part1.part2)中,我们学会了如何配置和 ...
- 分享一个js中的bind方法使用
来源:http://www.cnblogs.com/yuzhongwusan/archive/2012/02/13/2348782.html Js代码 复制代码 代码如下: var first_obj ...
- 获取项目中文件,存放到Debug中。
说起这个,还真是费了一般功夫. 说个最简单的方法: 第一步:把需要生成到Debug中的文件放到项目中(注意:当前文件夹目录是什么样的,存放到Debug中也是什么样) 第二部:设置文件属性中 复制到输出 ...
- iOS 沙盒(sandbox)结构 使用 实例
声明:该文档是经过自己查找网上的资料以及自己多年的经验后而总结出来的,希望对大家有所帮助,有什么不恰当支出还请大家多指点! iOS中的沙盒机制(SandBox)是一种安全体系,它规定了应用程序只能在为 ...
- JS实现动态提示文本框可输入剩余字数(类似发表微博数字提示)
一.实现效果: 为了更直观的体现用户在文本框输入文本时能看到自己输入了多少字,项目中需要通过判断提示文本框剩余可输入字数. html & JS: <div> <textare ...
- angular+ionic返回上一页并刷新
假定当前页面为editCata页面,要返回的是cataDetail页面.目前我找到两种方法实现返回上一页并刷新,如果以后有其它方法,再继续添加. 1.在editCataCtrl.js中注入$ionic ...
- 3个div 宽度移入移出时变化
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- nginx下开启pathinfo模式
第一种方式是通过重写url来实现pathinfo模式: location / { if (!-e $request_filename){ rewrite ^/(.*)$ /index.php?s=/$ ...