//

//  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. [TSOI2005]Exhibit

    问题描述 博览馆正在展出由世上最佳的 M 位画家所画的图画. wangjy 想到博览馆去看这几位大师的作品. 可是,那里的博览馆有一个很奇怪的规定,就是在购买门票时必须说明两个数字, a 和 b ,代 ...

  2. HDU FatMouse's Speed 基本DP

    题意:要求找到的体重递增,速度递减的老鼠,并且输出最长的长度数,而且输出各自的序列数.Special Judge 思路:先按体重由小到大排序,再找最长速度递减序列. 转移方程:mou[i].w> ...

  3. Google Code Jam 第一题

    通过的第一题,留做纪念,呵呵,非常简单,Africa 2010, Qualification Round: Store Credit. #include <stdio.h> #includ ...

  4. 创建二叉树,C语言实现

    一.前序遍历创建二叉树,使用递归,头文件 BiTree.h /*槽点一:创建树时用scanf输入不成功*/ #ifndef BITREE_H #define BITREE_H #include< ...

  5. ios 免书籍入门站点

    http://www.raywenderlich.com/tutorials http://www.raywenderlich.com/ios-tutorials http://web.stanfor ...

  6. jQuery进行图片预先加载

    /** **将图片加载到内存中,在页面任何位置引用的时候,直接从缓存中读取,提升用户的体验,提高网站的流畅度.** **/ <!DOCTYPE html PUBLIC "-//W3C/ ...

  7. CSS- 兼容样式记录

    前面加* 或者_,不是CSS的正常写法,而是利用IE的解析BUG,从而实现所需要的效果.应尽量避免使用吧.* margin-left:32px; /*所有浏览器*/*margin-left:32px; ...

  8. linux命令之nohup

    功能: 使进程在退出登录后仍旧继续执行,nohup就是不挂起的意思(no hang up). 格式:$nohup command 和 $nohup command & 两种,二者之间的区别就是 ...

  9. 动态获取jar文件的路径

    下面专门封装了一个类来处理: import  java.io.File; /** * 获取打包后jar的路径信息 * @author Administrator *  2011-01-16 13:53 ...

  10. PHP同时操作两个mysql数据库

    $connect=mysql_connect("localhost","root","",true); $db=mysql_select_d ...