//

//  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. ab的排列 aa , ab ba,bb

    package reverseList; public class Main { static void perm(char c[],int lev,char ans[]) { if(c.length ...

  2. Kafka系列(一)安装和配置说明

    单机模式 修改kafak安装文件中 .../kafka_2.9.2-0.8.1.1/config 下面的server.properties 配置文件 1.broker.id=0   [默认不用修改,该 ...

  3. 利用gdb 调试android jni c动态库

    http://blog.dornea.nu/2015/07/01/debugging-android-native-shared-libraries/ Since I haven't done thi ...

  4. A Tour of Go Short variable declarations

    Inside a function, the := short assignment statement can be used in place of a var declaration with ...

  5. freemaker分页模板

    <link href="${base}/res/pra/css/style.css" rel="stylesheet" type="text/c ...

  6. vijos 1464 NOIP 1997 积木游戏

    背景 1997年全国青少年信息学(计算机)奥林匹克竞赛试题 第二试 描述 积木游戏 SERCOI 最近设计了一种积木游戏.每个游戏者有N块编号依次为1 ,2,…,N的长方体积木.对于每块积木,它的三条 ...

  7. JSON与JAVA数据的相互转换

    http://www.cnblogs.com/linjiqin/archive/2011/09/19/2181408.html import net.sf.json.JSONArray; import ...

  8. javascript Deferred和递归次数限制

    function runAsyncTTS(text,speecher,audiopath) { var def = jQuery.Deferred(); var args = {"Synth ...

  9. Sql Server2005 Transact-SQL 窗口函数(OVER)

    1.简介: SQL Server 2005中的窗口函数帮助你迅速查看不同级别的聚合,通过它可以非常方便地累计总数.移动平均值.以及执行其它计算.窗口函数功能非常强大,使用起来也十分容易.可以使用这个技 ...

  10. cocos2d-x游戏开发实战原创视频讲座系列1之2048游戏开发

     cocos2d-x游戏开发实战原创视频讲座系列1之2048游戏开发 的产生 视持续更新中.... 视频存放地址例如以下:http://ipd.pps.tv/user/1058663622     ...