//

//  ViewController.m

//  05-手势

//

//  Created by wanghy on 15/9/21.

//  Copyright (c) 2015年 wanghy. All rights reserved.

//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView* imageView;

@end

@implementation ViewController

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

// 1.创建一个手势的对象

// 2.把手势的对象添加到需要手势的view当中

// 3.实现手势的方法

//UITapGestureRecognizer(敲击)-------------

//    // 1.创建手势的对象

//    UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];

//    // 几根手指

//    tap.numberOfTouchesRequired = 2;

//    // 点几次

//    tap.numberOfTapsRequired = 2;

//    // 2.对imageView添加手势

//    [self.imageView addGestureRecognizer:tap];

//    // 3.实现方法

//UISwipeGestureRecognizer(轻扫)-------------

// 1.

UISwipeGestureRecognizer* swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];

UISwipeGestureRecognizer* swipe1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];

// 往左滑

swipe.direction = UISwipeGestureRecognizerDirectionLeft;

// 2.

[self.imageView addGestureRecognizer:swipe];

[self.imageView addGestureRecognizer:swipe1];

//UILongPressGestureRecognizer(长按)-------------

// 1.

UILongPressGestureRecognizer* longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];

// 长按多长时间执行方法

longPress.minimumPressDuration = 2;

// 误差

longPress.allowableMovement = 10;

// 2.

[self.imageView addGestureRecognizer:longPress];

//UIRotationGestureRecognizer(旋转)-------------

// 1

UIRotationGestureRecognizer* rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)];

// 2.

[self.imageView addGestureRecognizer:rotation];

//UIPinchGestureRecognizer(捏合,用于缩放)-------------

//1.

UIPinchGestureRecognizer* pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];

// 2.

[self.imageView addGestureRecognizer:pinch];

//UIPanGestureRecognizer(拖拽)-------------

// 1.

UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];

// 2.

[self.imageView addGestureRecognizer:pan];

}

// 拖拽

- (void)pan:(UIPanGestureRecognizer*)sender

{

CGPoint p = [sender translationInView:self.imageView];

self.imageView.transform = CGAffineTransformTranslate(self.imageView.transform, p.x, p.y);

[sender setTranslation:CGPointZero inView:self.imageView];

}

// 捏合

- (void)pinch:(UIPinchGestureRecognizer*)sender

{

//    self.imageView.transform = CGAffineTransformMakeScale(sender.scale, sender.scale);

self.imageView.transform = CGAffineTransformScale(self.imageView.transform, sender.scale, sender.scale);

sender.scale = 1;

}

// 旋转

- (void)rotation:(UIRotationGestureRecognizer*)sender

{

NSLog(@"%f", sender.rotation);

self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, sender.rotation);

sender.rotation = 0;

//    self.imageView.transform = CGAffineTransformMakeRotation(sender.rotation);

}

// 长按

- (void)longPress:(UILongPressGestureRecognizer*)sender

{

// 只是想让开始的时候执行某个代码 需要判断 手势的状态

if (sender.state == UIGestureRecognizerStateBegan) {

NSLog(@"longPress");

}

}

// 轻扫

- (void)swipe:(UISwipeGestureRecognizer*)sender

{

if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {

NSLog(@"left");

}

else {

NSLog(@"right");

}

}

// 敲击

- (void)tap:(UITapGestureRecognizer*)sender

{

NSLog(@"tap");

}

@end

IOS开发中针对UIImageView的几种常用手势的更多相关文章

  1. IOS开发中数据持久化的几种方法--NSUserDefaults

    IOS开发中数据持久化的几种方法--NSUserDefaults IOS 开发中,经常会遇到需要把一些数据保存在本地的情况,那么这个时候我们有以下几种可以选择的方案: 一.使用NSUserDefaul ...

  2. iOS开发中关于nslog的几种流行做法小结

    不管哪种方法,都必须在PCH文件中做下宏定义 DEBUG和RELEASE要分开,RELEASE时log打印要取消 方法一:简单直接,用几行代码搞定,简洁但功能少 #ifdef DEBUG #defin ...

  3. 怎样实现IOS开发中的数据存储方式

    iOS 开发中,一般有如下几种数据存储方式.需要根据具体的业务场景,选择 合适的数据存储方式. (1)  用户默认设置 – 这种情况通常不需要用户干预,如游戏通关信息,Video 播放记录,或者 Ap ...

  4. iOS开发中六种手势识别

    iOS开发中手势识别有六种: 轻击手势(TapGestureRecognizer), 轻扫手势 (SwipeGestureRecognizer), 长按手势(LongPressGestureRecog ...

  5. iOS开发UI篇—iOS开发中三种简单的动画设置

    iOS开发UI篇—iOS开发中三种简单的动画设置 [在ios开发中,动画是廉价的] 一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView b ...

  6. iOS开发中的4种数据持久化方式【二、数据库 SQLite3、Core Data 的运用】

                   在上文,我们介绍了ios开发中的其中2种数据持久化方式:属性列表.归档解档.本节将继续介绍另外2种iOS持久化数据的方法:数据库 SQLite3.Core Data 的运 ...

  7. iOS开发中的4种数据持久化方式【一、属性列表与归档解档】

    iOS中的永久存储,也就是在关机重新启动设备,或者关闭应用时,不会丢失数据.在实际开发应用时,往往需要持久存储数据的,这样用户才能在对应用进行操作后,再次启动能看到自己更改的结果与痕迹.ios开发中, ...

  8. iOS 开发中常见的设计模式

    最近有小伙伴问到在iOS开发中的几种设计模式,这里摘录一下别人的总结(因为已经感觉总结得差不多了,适用的可以阅读一下) 首先是开发中的23中设计模式分为三大类:1.创建型 2.结构型 3.行为型 (i ...

  9. iOS开发中遇到的一些问题及解决方案【转载】

    iOS开发中遇到的一些问题及解决方案[转载] 2015-12-29 [385][scrollView不接受点击事件,是因为事件传递失败] // //  MyScrollView.m //  Creat ...

随机推荐

  1. 【原】日志处理-Spark

    日志信息如下所示: 1.1.1.1 - - [21/Jul/2014:10:00:00 -0800] "GET /majihua/article/284234 HTTP/1.1"  ...

  2. Class.forName()数据库驱动

    在学习jdbc中,用到Class.forName(驱动);,当时学习的时候知道Class.forName就是加载一个类到虚拟机,在加载一个类的时候,这个类的信息会被放到一个方法区,一个CLass 在J ...

  3. git日常操作

    0.准备工作 0.1 git安装 http://git-scm.com/download/   图形客户端建议使用source tree,中文界面 http://www.sourcetreeapp.c ...

  4. python 多行字符串

    字符串是要用引号(双引号,单引号,多行用三个引号)引起来 TypeError: not enough arguments for format string you have to specify m ...

  5. HTTPResponse.read([amt]):只能read一次

    业务需要:我要写个tanx模拟器,给DSP发竞价请求. 下面是部分代码: def PostDataToDSP(self,url,postdata): headers = { 'Content-Type ...

  6. hdu 3183 A Magic Lamp(RMQ)

    题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且 ...

  7. 开发XMPP IM

    Openfire 是一个用Java 实现的XMPP 服务器,客户端可以通过IQ的方式与其进行通信(其实就是XML),客户端和服务器之间的通信是依靠底层Smack 库提供的各种功能来完成的.其实利用插件 ...

  8. excel导入数据库iis设置

    导入成功以后,基本这个小项目的所有功能都开发完成了,请IT部门帮我设定了一个固定IP,我以本机作为服务器,在本机IIS上发布了一个测试版,结果上传Excel数据报错, 错误信息“未在本地计算机上注册“ ...

  9. centos 5.4 安装nodejs + npm(转)

    而在安装nodejs的时候,需要用到,所以需要手动安装bz2库. sudo yum install -y bzip2* cd Python-/Modules/zlib ./configure make ...

  10. 我们应该如何去了解JavaScript引擎的工作原理 系列

    http://www.nowamagic.net/librarys/veda/detail/1579