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 ...
随机推荐
- JDK1.5新特性(二)……Static Import
援引 Static Import - This facility lets you avoid qualifying static members with class names without t ...
- Java笔记(十八)……包
概述 对类文件进行分类管理. 给类提供多层命名空间. 写在程序文件的第一行. 类名的全称的是 包名.类名. 包也是一种封装形式. 访问权限 引用<The Complete Reference&g ...
- Linux设备驱动编程中的中断与定时器处理
所谓中断是指CPU在执行过程中,出现某些突发时间急待处理,CPU必须暂停执行当前的程序,转去处理突发事件,处理完毕后CPU又返回原程序被中断的位置并继续执行. 中断分为(根据中断源来分): 内部中断 ...
- 《Genesis-3D开源游戏引擎--横版格斗游戏制作教程03:碰撞检测》
3.碰撞检测 碰撞检测的概述: 碰撞在物理学中表现为两粒子或物体间极端的相互作用.而在游戏世界中,游戏对象在游戏世界自身并不受物理左右,为了模拟真实世界的效果,需要开发者为其添加属性,以模拟真实事件的 ...
- POJ1006 - Biorhythms(中国剩余定理)
题目大意 略...有中文... 题解 就是解同余方程组 x≡(p-d)(mod 23) x≡(e-d)(mod 28) x≡(i-d)(mod 33) 最简单的中国剩余定理应用.... 代码: #in ...
- 最简单的基于FFMPEG的音频编码器(PCM编码为AAC)
http://blog.csdn.net/leixiaohua1020/article/details/25430449 本文介绍一个最简单的基于FFMPEG的音频编码器.该编码器实现了PCM音频采样 ...
- mysql 中文乱码的解决办法
I would not suggest Richies answer, because you are screwing up the data inside the database. You wo ...
- CodeForces 352D. Jeff and Furik
题意:给n个数,第一个人选取相邻两个递降的数交换顺序,第二个人一半的概率选取相邻两个递降的数交换顺序,一半的概率选取相邻两个递增的数交换顺序.两个人轮流操作,求整个数列变成递增数列所需交换次数的期望. ...
- stream转byte数组几种方式
第一种,写法最简单的.使用原生IO,一个字节一个字节读: //一个字符一个字符读,太慢 int i; while((i=in.read()) != -1){ i = in.read(); arr[j+ ...
- VC++从入门到精通视频教程网址
视频教程网址:http://www.pconline.com.cn/pcedu/empolder/gj/vc/0607/820674.html