//

//  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. F(x)

    Problem Description For a decimal number x with n digits (AnAn-1An-2 ... A2A1), we define its weight ...

  2. [TYVJ1827]『Citric II』一道防AK好题

    时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 第二届『Citric杯』NOIP提高组模拟赛第一题 描述 Lemon认为在第一届『Citric』杯模拟赛中出的 ...

  3. Java笔记(二十二)……Collection集合

    概述 为什么会出现集合类 面向对象语言对事物的体现都是以对象的形式,所以为了方便对多个对象的操作,就对对象进行存储,集合就是存储对象最常用的一种方式 数组和集合类同是容器,有何不同 数组虽然也可以存储 ...

  4. C++中构造函数和析构函数调用的时机

    今天看书忽然对这个地方有点模糊,尤其是析构函数在调用默认的析构函数和用户自己覆写的析构函数的时候有点意识模糊呢.写段代码总结下 #include <iostream> using name ...

  5. HW3.18

    import javax.swing.JOptionPane; public class Solution { public static void main(String[] args) { Str ...

  6. SQL SERVER全面优化

    今天我们从语句的一些优化写法及一些简单优化方法做一个介绍.这对于很多开发人员来说还是很有用的!为了方便阅读给出前文链接: SQL SERVER全面优化-------Expert for SQL Ser ...

  7. String的点点滴滴

    一.String 的 equals()到底比较的是什么?equals() 与 == 的区别? 当使用关系运算符==比较两个对象时,是比较两个对象使用的内存地址和内容是否相同,如果两个对象使用的是同一个 ...

  8. 更改 Tomcat 日志路径

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  9. Android - TextView Ellipsize属性

    Android - TextView Ellipsize属性 本文地址: http://blog.csdn.net/caroline_wendy android:ellipsize属性: If set ...

  10. 路冉的JavaScript学习笔记-2015年1月23日

    1.JavaScript的数据类型 A.原始类型:包含数值.字符串.布尔值.空值(null)和未定义值(undefined). Js原始类型均为不可改变类型.对不可变类型调用任何自带方法都不会改变原始 ...