IOS开发中针对UIImageView的几种常用手势
//
// 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的几种常用手势的更多相关文章
- IOS开发中数据持久化的几种方法--NSUserDefaults
IOS开发中数据持久化的几种方法--NSUserDefaults IOS 开发中,经常会遇到需要把一些数据保存在本地的情况,那么这个时候我们有以下几种可以选择的方案: 一.使用NSUserDefaul ...
- iOS开发中关于nslog的几种流行做法小结
不管哪种方法,都必须在PCH文件中做下宏定义 DEBUG和RELEASE要分开,RELEASE时log打印要取消 方法一:简单直接,用几行代码搞定,简洁但功能少 #ifdef DEBUG #defin ...
- 怎样实现IOS开发中的数据存储方式
iOS 开发中,一般有如下几种数据存储方式.需要根据具体的业务场景,选择 合适的数据存储方式. (1) 用户默认设置 – 这种情况通常不需要用户干预,如游戏通关信息,Video 播放记录,或者 Ap ...
- iOS开发中六种手势识别
iOS开发中手势识别有六种: 轻击手势(TapGestureRecognizer), 轻扫手势 (SwipeGestureRecognizer), 长按手势(LongPressGestureRecog ...
- iOS开发UI篇—iOS开发中三种简单的动画设置
iOS开发UI篇—iOS开发中三种简单的动画设置 [在ios开发中,动画是廉价的] 一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView b ...
- iOS开发中的4种数据持久化方式【二、数据库 SQLite3、Core Data 的运用】
在上文,我们介绍了ios开发中的其中2种数据持久化方式:属性列表.归档解档.本节将继续介绍另外2种iOS持久化数据的方法:数据库 SQLite3.Core Data 的运 ...
- iOS开发中的4种数据持久化方式【一、属性列表与归档解档】
iOS中的永久存储,也就是在关机重新启动设备,或者关闭应用时,不会丢失数据.在实际开发应用时,往往需要持久存储数据的,这样用户才能在对应用进行操作后,再次启动能看到自己更改的结果与痕迹.ios开发中, ...
- iOS 开发中常见的设计模式
最近有小伙伴问到在iOS开发中的几种设计模式,这里摘录一下别人的总结(因为已经感觉总结得差不多了,适用的可以阅读一下) 首先是开发中的23中设计模式分为三大类:1.创建型 2.结构型 3.行为型 (i ...
- iOS开发中遇到的一些问题及解决方案【转载】
iOS开发中遇到的一些问题及解决方案[转载] 2015-12-29 [385][scrollView不接受点击事件,是因为事件传递失败] // // MyScrollView.m // Creat ...
随机推荐
- Hadoop HDFS的常用命令
1.将目录/root/data/下的item.txt复制到HDFS下的/user/root下: hadoop fs -copyFromLocal /root/data/item.txt itemdat ...
- NOIP2001 一元三次方程求解
题一 一元三次方程求解(20分) 问题描述 有形如:ax3+bx2+cx+d=0 这样的一个一元三次方程.给出该方程中各项的系数(a,b,c,d 均为实数),并约定该方程存在三个不同实根(根的范 ...
- Codeforces149D - Coloring Brackets(区间DP)
题目大意 要求你对一个合法的括号序列进行染色,并且需要满足以下条件 1.要么不染色,要么染红色或者蓝色 2.对于任何一对括号,他们当中有且仅有一个被染色 3.相邻的括号不能染相同的颜色 题解 用区间d ...
- mysql均衡负载
一.利用mysql 复制分流查询操作: 利用mysql的主从复制可以有效的分流更新操作和查询操作,具体的实现是一个主服务器,承担更新操作,多台从服务器,承担查询操作,主从之间通过复制实现数据的同步.多 ...
- D3D游戏编程系列(三):自己动手编写即时战略游戏之寻路
说起即时战略游戏,不得不提的一个问题是如何把一个物体从一个位置移动到另一个位置,当然,我说的不是瞬移,而是一个移动的过程,那么在这个移动的过程中我们如何来规划路线呢,这就不得不提到寻路了. 我所了解到 ...
- 用document.title=“xxx”动态修改title,在ios的微信下面不生效
单页应用里整个页面只会在第一次完全刷新,后面只会局部刷新(一般不包括head及里面的title),所以无法在服务器端控制title,只能在页面刷新的时候通过js修改title.常规做法如下,可惜在iO ...
- Java获取一个路径下指定后缀名的所有文件
方法一: http://blog.csdn.net/zjx102938/article/details/8114114 import java.io.File; import java.util.Ar ...
- 【转】C++中了类继承和调用父类的构造函数方法
构造方法用来初始化类的对象,与父类的其它成员不同,它不能被子类继承(子类可以继承父类所有的成员变量和成员方法,但不继承父类的构造方法).因此,在创建子类对象时,为了初始化从父类继承来的数据成员,系统需 ...
- 对Jsp提交input标签空格和回车的处理
今天做增加的时候发现一个问题,在js中去掉空格的时候如果这么写 var stage_name = document.getElementById("stage_name").val ...
- [Angular 2] ROUTING IN ANGULAR 2 REVISITED
Let's say we have a list of contacts, click each contact, we can render a new route to get the detai ...