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 ...
随机推荐
- SQL Server 2008如何进行数据库同步?
复制有三种类:事务复制.快照复制.合并复制.事务复制是将复制启用后的所有发布服务器上发布的内容在修改时传给订阅服务器,数据更改将按照其在发布服务 器上发生的顺序和事务边界,应用于订阅服务器,在发布内部 ...
- 算法导论学习-RED-BLACK TREE
1. 红黑树(RED-BLACK TREE)引言: ------------------------------------- 红黑树(RBT)可以说是binary-search tree的非严格的平 ...
- Kooboo 加Search功能 必须先ReBuild Index Data
加Search功能 有几个要点 1. 需要在Kooboo 必须先 ReBuild Index Data 2. 需要在要搜索的page中启用搜索索引 搜索的代码 @using K ...
- poj 2367 Genealogical tree (拓扑排序)
火星人的血缘关系很奇怪,一个人可以有很多父亲,当然一个人也可以有很多孩子.有些时候分不清辈分会产生一些尴尬.所以写个程序来让n个人排序,长辈排在晚辈前面. 输入:N 代表n个人 1~n 接下来n行 第 ...
- Blot消息处理者
- oracle中exp,imp的使用详解
http://www.cnblogs.com/yugen/archive/2010/07/25/1784763.html
- Objective-C-使用NSMutableURLRequest发送POST请求,使用NSJSONSerialization解析JSON字符串
NSString *reqData = @"Data="; NSData *postDatas = nil; NSString *urlPath = @"url" ...
- linux中配置maven环境
一 . 下载maven http://maven.apache.org/download.cgi 二. 将maven解压到你的工具文件夹下 如我是解压到: /home/urc/tool下 三. ...
- eclipse 插件之Code Folding
功能: eclipse自带折叠包括方法, import, 注释等得折叠功能, code folding 插件对其增强. 1. 下载插件:( 也可以用link方式, 我的是link安装, jar包网上很 ...
- IOS tableView 自定义cell 多行时 文字重复现象
今天写了一个demo,有一个问题,有很多cell,但是超过一页后往下翻,发现文字有重叠现象, cell用的是重用机制,按说不会这样,最终解决的方案: 勾选这个,clears graphics cont ...