ios手势复习值之换图片-转场动画(纯代码)
目标:实现通过手势进行图片的切换 通过左扫右扫 来实现(纯代码)
添加三个属性 1uiImageView 用来显示图片的view
2 index 用来表示图片的索引
3 ISLeft 判断是不是向左滑
下边是详细的代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.index = 0;
self.ISLeft = YES;
_imageView = [[UIImageView alloc]initWithFrame:self.view.frame];
// _imageView.backgroundColor = [UIColor redColor];
_imageView.contentMode = UIViewContentModeScaleAspectFit;//合适的大小
self.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.png",_index]];
[self.view addSubview:_imageView];
//用户交互设置
self.imageView.userInteractionEnabled = YES;
//添加扫动得手势
UISwipeGestureRecognizer *swipL = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swip:)];
swipL.direction = UISwipeGestureRecognizerDirectionLeft;
[self.imageView addGestureRecognizer:swipL];
UISwipeGestureRecognizer *swipR = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swip:)];
swipR.direction = UISwipeGestureRecognizerDirectionRight;
[self.imageView addGestureRecognizer:swipR];
}
设置转场动画 :在手势里边进行实现
手势的实现以及转场动画:
-(void)swip:(UISwipeGestureRecognizer *)sender
{
if(sender.direction == UISwipeGestureRecognizerDirectionLeft)
{
if(self.index>=0)
{
if(self.index>0)
{
self.index--;
}
else
{
self.index =3;
}
self.ISLeft = YES;
}
}
else
{
self.ISLeft = NO;
if(self.index<3)
{
self.index++;
if(self.index ==3)
{
self.index =0;
}
}
}
//转场动画
CATransition *trans = [[CATransition alloc]init];
//转场动画的类型
trans.type =@"push";
//判断是不是向左滑
if(self.ISLeft)
{
trans.subtype = kCATransitionFromTop;
}
else
{
trans.subtype = kCATransitionFromBottom;
}
trans.duration = 0.5f;
[self.imageView.layer addAnimation:trans forKey:@"trans"];
//切换图画
self.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",_index]];
}
ios手势复习值之换图片-转场动画(纯代码)的更多相关文章
- iOS:UIView的block函数实现转场动画---单视图
使用UIView动画函数实现转场动画——单视图 + (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration ...
- iOS:UIView的block函数实现转场动画---双视图
使用UIView动画函数实现转场动画——双视图 + (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView durati ...
- UIView封装动画--iOS利用系统提供方法来做转场动画
UIView封装动画--iOS利用系统提供方法来做转场动画 UIViewAnimationOptions option; if (isNext) { option=UIViewAnimationOpt ...
- iOS:核心动画之转场动画CATransition
转场动画——CATransition CATransition是CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果.iOS比Mac OS X的转场动画效果少一点 U ...
- iOS 自定义转场动画浅谈
代码地址如下:http://www.demodashi.com/demo/11612.html 路漫漫其修远兮,吾将上下而求索 前记 想研究自定义转场动画很久了,时间就像海绵,挤一挤还是有的,花了差不 ...
- 一行代码实现自定义转场动画--iOS自定义转场动画集
WXSTransition 这款非常不错,力推 这是作者源码简书地址: http://www.jianshu.com/p/fd3154946919 这是作者源码github地址 https://git ...
- iOS开发系列--无限循环的图片浏览器
--UIKit之UIScrollView 概述 UIKit框架中有大量的控件供开发者使用,在iOS开发中不仅可以直接使用这些控件还可以在这些控件的基础上进行扩展打造自己的控件.在这个系列中如果每个控件 ...
- ios手势
iOS 手势操作:拖动.捏合.旋转.点按.长按.轻扫.自定义 大 中 小 1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. i ...
- iOS 手势操作:拖动、捏合、旋转、点按、长按、轻扫、自定义
1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureReco ...
随机推荐
- Android网络框架Volley(体验篇)
Volley是Google I/O 2013推出的网络通信库,在volley推出之前我们一般会选择比较成熟的第三方网络通信库,如: android-async-http retrofit okhttp ...
- [LeetCode#204]Factorial Trailing Zeroes
Problem: Description: Count the number of prime numbers less than a non-negative number, n. Analysis ...
- css3倒影
使用CSS3制作倒影 img { -webkit-box-reflect: below 0px -webkit-gradient(linear, left top, left bottom, from ...
- (转载)不能启动虚拟机 Unable to open kernel device "\\.\Global\vmx86
(转载)http://blog.csdn.net/shenghuiping2001/article/details/7083153 今天系统加了内存条,设置变了一下: 就启动不起虚拟机了,报错: Un ...
- HDOJ/HDU 2560 Buildings(嗯~水题)
Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...
- c语言中static的语义
1.static变量: 1).局部 a.静态局部变量在函数内定义,生存期为整个源程序,但作用域与自动变量相同,只能在定义该变量的函数内使用.退出该函数后, 尽管该变量还继续存在,但不能使用它. b.对 ...
- HDU 1230 火星A+B
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1230 水题模拟一道,主要考验代码能力,刷完题就感觉自己还是太弱了. #include<cmath ...
- NET设计模式-单例模式(Singleton Pattern)
1. 概述 Singleton Pattren 要求一个类有且仅有一个实例,并且提供一个全局变量.这个创建的对象是独一无二的,在这个单独对象实例中,集中所创建类的所有属性和方法. 在创建一个单例,何时 ...
- 【Android - V】之SwipeRefreshLayout的使用
SwipeRefreshLayout是Android V4.V7包中的一个控件,是Google给我们提供的一个下拉刷新的布局控件,可以轻松完成下拉刷新. SwipeRefreshLayout的特点是其 ...
- JS时钟钟表
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...