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 ...
随机推荐
- FP树(附)
Apriori算法和FPTree算法都是数据挖掘中的关联规则挖掘算法,处理的都是最简单的单层单维布尔关联规则. 转自http://blog.csdn.net/sealyao/article/detai ...
- winpcap使用之捕获数据包
第一种方法,调用回调函数 #include "pcap.h" /* packet handler 函数原型 */ void packet_handler(u_char *param ...
- FZU Problem 2125 简单的等式
思路:x绝对小于根号n,再由s(x,m)可以缩小范围.1e9十六进制大约算出每位和相加100左右.这种题直接判断范围再暴力. #include<stdio.h> #include<s ...
- Android 多线程 异步加载
Android 应用中需要显示网络图片时,图片的加载过程较为耗时,因此加载过程使用线程池进行管理, 同时使用本地缓存保存图片(当来回滚动ListView时,调用缓存的图片),这样加载和显示图片较为友好 ...
- advanced dom scripting dynamic web design techniques Part One DOM SCRIPTING IN DETAIL CHAPTER 1 DO IT RIGHT WITH BEST PRACTICES
You’re excited; your client is excited. All is well. You’ve just launched the client’s latest websit ...
- poj 2117 Electricity【点双连通求删除点后最多的bcc数】
Electricity Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4727 Accepted: 1561 Descr ...
- 从app里跳到appstore评论页面的实现
// 如果要实现在应用里面跳到appstore的对应评论页面里面的话,只要将下面地址中App_ID替换成自己的id就可以了,其他的地方都不用管. // 如果要用Safari浏览器做实验的话可以将地址中 ...
- 适合高级Java程序员看的12本书
1.Thinking in Java 2.Head First Java 3.Java in a Nutshell 4.The elements of Java style 5.Effective J ...
- [学习笔记]--Jfinal 表单提交附件
近期.项目里面用到了Jfinal 里面的上传附件. Jfinal 的Controller 里面提供了一个 getFile系列方法提供文件上传. 我这里呢,是文件上传和表单參数一起提交. 页面类似下图: ...
- “cvSnakeImage”: 找不到标识符
1>g:\project\opencv\helloopencv\helloopencv\helloopencv.cpp(74) : error C2065: "CV_VALUE&quo ...