文章只要你有一点点基础应该就可以看的懂,文章只为学习交流

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic,retain)UIImageView *imageView;
@property (nonatomic,assign)NSInteger index;//下标
@property (nonatomic,retain)NSMutableArray *images;//图片名 字数组 @end @implementation ViewController
#加载视图 -(void)viewDidLoad
{ [super viewDidLoad];
//布局imageView
[self layoutImageView];
//1.创建轻拍手势
[self tapGestureRecognizer];
//2.创建清扫手势
[self swipeGestureRecognizer];
//3.创建长安手势
[self longPressGestureRecognizer];
//4.创建平移手势
[self panGestureTecognizer];
//5.创建捏合手势
[self pinchGestureRecognizer];
//6.创建 旋转手势
[self rotationGestureRecognizer]
//7.创建边缘手势
[self screenEdgePanGestureRecognizer];

}

##布局ImageView

-(void)layoutImageView
{ //创建对象
UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)];
//配置属性
imageView.backgroundColor =[UIColor purpleColor];
//设置图片
imageView.image =[UIImage imageNamed:@"car1.jpg"];
//添加父视图
[self.view addSubview:imageView];
//将创建的图片视图对象 给属性赋值
self.imageView =imageView;
//打开用户交互
self.imageView.userInteractionEnabled =YES;
self.images =[NSMutableArray array];
for (int i = 1; i<9; i++) {
NSString * imageName =[NSString stringWithFormat:@"car%d.jpg",i];
[_images addObject:imageName];
}
// _index =1; } #pragma 轻怕手势
//创建轻拍手势
-(void)tapGestureRecognizer
{ //创建手势对象
UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
//配置属性
//轻拍次数
tap.numberOfTapsRequired =1;
//轻拍手指个数
tap.numberOfTouchesRequired =1;
//讲手势添加到指定的视图上
[_imageView addGestureRecognizer:tap]; } //轻拍事件 -(void)tapAction:(UITapGestureRecognizer *)tap
{ //图片切换
NSLog(@"拍一下");
_index ++;
if (_index == 8) {
_index = 1;
}
self.imageView.image =[UIImage imageNamed:_images[_index]]; }
#pragma 清扫手势 //清扫手势
-(void)swipeGestureRecognizer
{ UISwipeGestureRecognizer *swipe =[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
//配置属性
//一个清扫手势 只能有两个方向(上和下) 或者 (左或右)
//如果想支持上下左右清扫 那么一个手势不能实现 需要创建两个手势
swipe.direction =UISwipeGestureRecognizerDirectionLeft;
//添加到指定视图
[_imageView addGestureRecognizer:swipe];
UISwipeGestureRecognizer *swipe2 =[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
swipe2.direction =UISwipeGestureRecognizerDirectionRight;
[_imageView addGestureRecognizer:swipe2]; }
//清扫事件
-(void)swipeAction:(UISwipeGestureRecognizer *)swipe
{ NSLog(@"扫一下");
if (swipe.direction ==UISwipeGestureRecognizerDirectionRight) {
NSLog(@"右清扫");
_index --;
if (_index < 1) {
_index =7;
}
_imageView.image =[UIImage imageNamed:_images[_index]];
}else if(swipe.direction == UISwipeGestureRecognizerDirectionLeft){
NSLog(@"左扫一下");
_index ++;
if (_index == 8) {
_index=1;
}
_imageView.image =[UIImage imageNamed:_images[_index]];
} }
#pragma 长按手势
//创建长按手势
-(void)longPressGestureRecognizer
{ UILongPressGestureRecognizer *longPress =[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];
//最短长按时间
longPress.minimumPressDuration =2;
//允许移动最大距离
longPress.allowableMovement =1;
//添加到指定视图
[_imageView addGestureRecognizer:longPress]; }
//长按事件
-(void)longPressAction:(UILongPressGestureRecognizer *)longPress
{ //NSLog(@"长按");
//对于长安有开始和 结束状态
if (longPress.state == UIGestureRecognizerStateBegan) {
NSLog(@"长按开始");
//将图片保存到相册
UIImage *image =[UIImage imageNamed:_images[_index]];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}else if (longPress.state == UIGestureRecognizerStateEnded)
{
NSLog(@"长按结束");
} } #pragma 平移手势
//创建平移手势
-(void)panGestureTecognizer
{ UIPanGestureRecognizer *pan =[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
//添加到指定视图
[_imageView addGestureRecognizer:pan]; }
//创建平移事件
-(void)panAction:(UIPanGestureRecognizer *)pan
{ //获取手势的位置
CGPoint position =[pan translationInView:_imageView]; //通过stransform 进行平移交换
_imageView.transform = CGAffineTransformTranslate(_imageView.transform, position.x, position.y);
//将增量置为零
[pan setTranslation:CGPointZero inView:_imageView]; } #pragma 捏合手势
-(void)pinchGestureRecognizer
{ UIPinchGestureRecognizer *pinch =[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
//添加到指定视图
[_imageView addGestureRecognizer:pinch]; }
//添加捏合事件
-(void)pinchAction:(UIPinchGestureRecognizer *)pinch
{ //通过 transform(改变) 进行视图的视图的捏合
_imageView.transform =CGAffineTransformScale(_imageView.transform, pinch.scale, pinch.scale);
//设置比例 为 1
pinch.scale = 1; }
#pragma 旋转手势 //创建旋转手势
-(void)rotationGestureRecognizer
{ UIRotationGestureRecognizer *rotation =[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
//添加到指定的视图
[_imageView addGestureRecognizer:rotation]; }
//旋转事件 -(void)rotationAction:(UIRotationGestureRecognizer *)rote
{ //通过transform 进行旋转变换
_imageView.transform = CGAffineTransformRotate(_imageView.transform, rote.rotation);
//将旋转角度 置为 0
rote.rotation = 0; }
#pragma 边缘手势 //创建边缘手势
-(void)screenEdgePanGestureRecognizer
{ UIScreenEdgePanGestureRecognizer *screenPan = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenPanAction:)];
[_imageView addGestureRecognizer:screenPan]; }
//创建边缘事件
-(void)screenPanAction:(UIScreenEdgePanGestureRecognizer *)screenPan
{ NSLog(@"边缘"); } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

iOS学习必须了解的七大手势的更多相关文章

  1. iOS学习笔记——触控与手势

    触控 此部分内容已学良久,恨记之甚晚,忙矣,懒矣!本文简而记焉,恐日后忘也. 在iOS的触控事件中,有触控.事件以及响应者这三个角色,一个触摸则代表了一只手指和屏幕接触这个动作所包含的信息:而事件则包 ...

  2. iOS学习路线图

    一.iOS学习路线图   二.iOS学习路线图--视频篇       阶 段 学完后目标 知识点 配套学习资源(笔记+源码+PPT) 密码 基础阶段 学习周期:24天       学习后目标:    ...

  3. ios学习之UISwipeGestureRecognizer手势识别

    ios学习之UISwipeGestureRecognizer手势识别   本文部分转自俺是一个瓜娃!!!的博客UISwipeGestureRecognizer ---手指动作,转载过来仅是为了自己查询 ...

  4. iOS学习笔记-精华整理

    iOS学习笔记总结整理 一.内存管理情况 1- autorelease,当用户的代码在持续运行时,自动释放池是不会被销毁的,这段时间内用户可以安全地使用自动释放的对象.当用户的代码运行告一段 落,开始 ...

  5. iOS学习笔记总结整理

    来源:http://mobile.51cto.com/iphone-386851_all.htm 学习IOS开发这对于一个初学者来说,是一件非常挠头的事情.其实学习IOS开发无外乎平时的积累与总结.下 ...

  6. ios学习-delegate、传值、跳转页面

    ios学习-delegate.传值.跳转页面     1.打开xcode,然后选择ios--Application--Empty Application一个空项目. 项目目录: 2.输入项目名称以及选 ...

  7. iOS学习——UIView的研究

    在iOS开发中,我们知道有一个共同的基类——NSObject,但是对于界面视图而言,UIView是非常重要的一个类,UIView是很多视图控件的基类,因此,对于UIView的学习闲的非常有必要.在iO ...

  8. 2015最新iOS学习线路图

    iOS是由苹果公司开发的移动操作系统,以xcode为主要开发工具,具有简单易用的界面.令人惊叹的功能,以及超强的稳定性,已经成为iPhone.iPad 和iPod touch 的强大基础:iOS 内置 ...

  9. iOS学习——iOS原生实现二维码扫描

    最近项目上需要开发扫描二维码进行签到的功能,主要用于开会签到的场景,所以为了避免作弊,我们再开发时只采用直接扫描的方式,并且要屏蔽从相册读取图片,此外还在二维码扫描成功签到时后台会自动上传用户的当前地 ...

随机推荐

  1. 【cocos2d-js官方文档】二十、moduleConfig.json

    概述 该配置文件相当于v2版本号中的jsloader.js. 改造的目的是为了使得配置纯粹化,同一时候也能比較好的支持cocos-console.cocos-utils甚至是用户自己定义脚本工具. 字 ...

  2. Oracle新建Schema

    1.首先,创建(新)用户: create user username identified by password; username:新用户名的用户名 password: 新用户的密码也可以不创建新 ...

  3. java应用集锦9:httpclient4.2.2的几个常用方法,登录之后访问页面问题,下载文件

    转账注明出处:http://renjie120.iteye.com/blog/1727933 在工作中要用到android,然后进行网络请求的时候,打算使用httpClient. 总结一下httpCl ...

  4. hdoj--1018--Big Number(简单数学)

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  5. BZOJ 3230 后缀数组+ST

    思路: 首先我们已经会了后缀数组求本质不同的子串个数 这道题跟那个差不多 首先我们可以知道按字典序排好的每个后缀之前包含多少本质不同的字串 就是sigma(n-sa[i]+1-ht[i]+bi[i-1 ...

  6. POJ 3020 Hungary

    一道建图题-- // by SiriusRen #include <cstdio> #include <cstring> using namespace std; #defin ...

  7. c/s winform打包和部署

    1:vs2010新建  安装项目  左边出现3个文件夹 2:点击 第一个文件夹-> “应用程序文件夹”    将 bin 目录下的所以文件  拖进 右边的空白处:c:\windows\syste ...

  8. Python 接口类或抽象类 反射

    # 抽象类或者接口类,制定规范,统一方法名 # # 抽象类或者接口类,制定规范,统一方法名 from abc import ABCMeta,abstractmethod class Payrole(m ...

  9. Android 对ScrollView滚动监听,实现美团、大众点评的购买悬浮效果

    转帖请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming),请尊重他人的辛勤劳动成果,谢谢! 随着移动互联网的快速发展,它已经和我们的生活息息相关了,在 ...

  10. Xml实现图片旋转

    1. 需求:不使用Java代码,实现旋转图片动画 2.实现:使用Progressbar控件 3. anim/anim_loading.xml <?xml version="1.0&qu ...