2019独角兽企业重金招聘Python工程师标准>>>

  1. 点击手势和双击手势

  2. #import "TapViewController.h"

  3. @interface TapViewController ()

  4. @end

  5. @implementation TapViewController

  6. - (void)viewDidLoad {

  7. [super viewDidLoad];

  8. // Do any additional setup after loading the view.

  9. //点击手势:

  10. //=================单击===========

  11. //1.创建一个点击手势对象

  12. //UIGestureRecognizer是所有手势的父类,一般不会直接使用哪个它

  13. //而是使用它的子类

  14. //参数1:响应手势的对象;

  15. //参数2:响应的消息

  16. //功能:发生点击动作,对象去响应这个手势

  17. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer

  18. alloc]initWithTarget:self action:@selector(tapGesture:)];

  19. //2.添加手势到指定的视图上(任何手势都可以添加到任何继承自UIView的类的对象上)

  20. [self.view addGestureRecognizer:tapGesture];

  21. //=================双击===========

  22. //1.创建点击对象

  23. UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]

  24. initWithTarget:self action:@selector(doubleTap:)];

  25. //2.设置点击次数

  26. doubleTap.numberOfTapsRequired = 2;

  27. //4.忽略其他手势

  28. //单击的时候忽略双击;

  29. [tapGesture requireGestureRecognizerToFail:doubleTap];

  30. //3.将手势添加到指定的视图控制器上

  31. [self.view addGestureRecognizer:doubleTap];

  32. }

  33. #pragma mark -单击手势响应

  34. - (void)tapGesture:(UITapGestureRecognizer *)tap{

  35. //获取点击手势的坐标

  36. CGPoint point = [tap locationInView:self.view];

  37. // NSLog(@"%@",NSStringFromCGPoint(point));

  38. NSLog(@"单击");

  39. }

  40. #pragma mark - 双击事件响应

  41. - (void)doubleTap:(UIGestureRecognizer *)doubleTap{

  42. //获取点击手势的坐标

  43. CGPoint point = [doubleTap locationInView:self.view];

  44. //NSLog(@"%@",NSStringFromCGPoint(point));

  45. NSLog(@"双击");

  46. }

  47. @end


长按手势:关键在于设置手势的时间

#import "LongPressViewController.h"

@interface LongPressViewController ()

@end

@implementation LongPressViewController

- (void)viewDidLoad {

[super viewDidLoad];

//1.创建长按手势对象

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];

//3.设置长按时间

longPress.minimumPressDuration = 1;

//2.将手势添加到视图控制器上;

[self.view addGestureRecognizer:longPress];

}

#pragma mark -响应长按手势

//这个方法在手势的状态发生改变的时候调用

- (void)longPress : (UILongPressGestureRecognizer *)longPress{

//手势的状态:(针对所有的手势都适用)

//UIGestureRecognizerStateBegan:手势开始

//UIGestureRecognizerStateChanged:手势改变

//UIGestureRecognizerStateEnded:手势结束

//longPress setState:<#(UIGestureRecognizerState)#>

if (longPress.state == UIGestureRecognizerStateBegan) {

NSLog(@"长按");

}

//  NSLog(@"长按");

}

@end


滑动手势:关键在于设置滑动的方向

#import "SwipeViewController.h"

@interface SwipeViewController ()

@end

@implementation SwipeViewController

- (void)viewDidLoad {

[super viewDidLoad];

//1.创建滑动手势对象

UISwipeGestureRecognizer *swip = [[UISwipeGestureRecognizer alloc]

initWithTarget:self action:@selector(swipGesture:)];

//3.滑动方向

//注意:如果想要可以两个方向都可以,滑动方向必须添加一个右划的手势

[swip setDirection:UISwipeGestureRecognizerDirectionLeft];

//2.将手势添加到视图控制器上

[self.view addGestureRecognizer:swip];

//=============右划默认是从左向右滑动==========

UISwipeGestureRecognizer *swipRight = [[UISwipeGestureRecognizer alloc]

initWithTarget:self action:@selector(swipGesture:)];

// [swip setDirection:UISwipeGestureRecognizerDirectionRight];

[self.view addGestureRecognizer:swipRight];

}

#pragma mark - 滑动手势响应事件

- (void)swipGesture:(UISwipeGestureRecognizer *)swipGesture{

if (swipGesture.direction == UISwipeGestureRecognizerDirectionRight) {

NSLog(@"右滑回到下一页");

}else{

NSLog(@"左滑到上一页");

}

}

@end


拖动手势

#import "PanViewController.h"

@interface PanViewController ()

@end

@implementation PanViewController

- (void)viewDidLoad {

[super viewDidLoad];

//1.创建拖动手势对象

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc]

initWithTarget:self action:@selector(pan:)];

//2.添加到视图

[self.imageView addGestureRecognizer:panGesture];

}

//这个方法会在拖动过程中时时调用;

#pragma mark - 拖动手势方法

- (void)pan:(UIPanGestureRecognizer *)pan{

self.imageView.center = [pan locationInView:self.view];

NSLog(@"拖动");

}

@end


旋转手势:

#import "RotationViewController.h"

@interface RotationViewController ()

@end

@implementation RotationViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view.

//1.创建旋转手势对象

UIRotationGestureRecognizer *rotatioin = [[UIRotationGestureRecognizer alloc]

initWithTarget:self action:@selector(rotationG:)];

//2.添加到视图上

[self.imageView addGestureRecognizer:rotatioin];

}

#pragma mark - 旋转手势事件

- (void) rotationG:(UIRotationGestureRecognizer *)ro{

static CGFloat lastRotation = 0;

//® self.imageView.center = [rotation locationInView:self.view];

CGFloat triangle = ro.rotation + lastRotation;

self.imageView.transform = CGAffineTransformMakeRotation(triangle);

if (ro.state == UIGestureRecognizerStateEnded) {

lastRotation = ro.rotation + lastRotation;

}

NSLog(@"旋转");

}

@end


缩放手势

#import "PinchViewController.h"

@interface PinchViewController ()

@end

@implementation PinchViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view.

//1.创建pinch手势对象

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]

initWithTarget:self action:@selector(pinchGesture:)];

//2.添加到视图上

[self.view addGestureRecognizer:pinch];

}

- (void)pinchGesture:(UIPinchGestureRecognizer *)pinch{

static CGFloat lastScale =1;

CGFloat scale = pinch.scale;

//3.通过手势的缩放比例去改变图片的缩放形变;

[self.imageView setTransform:CGAffineTransformMakeScale(scale, scale)];

if (pinch.state == UIGestureRecognizerStateEnded) {

lastScale = pinch.scale * lastScale;

}

NSLog(@"缩放");

}

@end

转载于:https://my.oschina.net/luhoney/blog/666058

IOS开发之UI手势相关推荐

  1. IOS开发之UI基础LOL英雄展示-15

    IOS开发之UI基础LOL英雄展示-15 // // ViewController.m // 15-英雄展示-单组数据 // // Created by 鲁军 on 2021/2/3. //#impo ...

  2. iOS开发之UI开发(UITableView)

    UITableView 继承自UIScrollView,性能极佳 UITableView的两种样式 UITableViewStylePlain列表样式 UITableViewStyleGrouped ...

  3. (0107)iOS开发之UI实时调试InjectionIII的使用

    AppStore : 下载:Injectionlll 下载地址 使用步骤: 1.设置InjectionIII 打开InjectionIII工具,选择Open Project,选择你的代码所在的路径,然 ...

  4. (0010) iOS 开发之UI布局兼容 4s/5/6/7 屏幕解决方案

    iOS开发技术分享群 147787076 如上带标注的效果图,是1080*1920 也就是6p 的尺寸.如何根据6p的标注,在各种iPhone 尺寸上完美适配尼? 适用:UI 各屏幕/分辨率适配方案( ...

  5. iOS开发之AVKit框架使用

    2019独角兽企业重金招聘Python工程师标准>>> iOS开发之AVKit框架使用 一.引言 在iOS开发框架中,AVKit是一个非常上层,偏应用的框架,它是基于AVFounda ...

  6. (0045) iOS 开发之MBProgressHUD 源码学习

    (0045) iOS 开发之MBProgressHUD 源码学习 第一部分:学习所得和分析线程 1.  学习到了kvo 的使用 和屏幕方向的旋转判断. 2. 如果调起这个 HUD 的方法不是在主线程调 ...

  7. (0016)iOS 开发之Mac上Navicat Premium 创建远程连接和本地连接

    1.下载安装 (百度云盘里面有安装文件和注册机) 链接: https://pan.baidu.com/s/1kVG1k71 密码: mr5g 破解教程看这篇博客:http://blog.csdn.ne ...

  8. 李洪强iOS开发之RunLoop的原理和核心机制

    李洪强iOS开发之RunLoop的原理和核心机制 搞iOS之后一直没有深入研究过RunLoop,非常的惭愧.刚好前一阵子负责性能优化项目,需要利用RunLoop做性能优化和性能检测,趁着这个机会深入研 ...

  9. IOS开发之MD5加密和钥匙串的使用-oc

    IOS开发之MD5加密和钥匙串的使用-oc 源码在我的主页,md5加密是用户登录安全的一个保障.不可逆的,可以暴力破解的. // // ViewController.m // MD5演练 // // ...

最新文章

  1. shell脚本中获取当前所在目录地址
  2. 瞬间教你学会使用java中list的retainAll方法
  3. 潭州课堂25班:Ph201805201 并发(非阻塞,epoll) 第十课 (课堂笔记)
  4. linux创建名称为学号的文件,Linux操作系统下用户管理及文件管理.doc
  5. sql server 跟踪_SQL Server作业性能–跟踪
  6. [转载] 【python】str与json类型转换
  7. .net知识和学习方法系列(二十一)CLR-枚举
  8. 个人的Directx9研究总结 (1)
  9. java请假系统毕业设计_jsp企业员工考勤管理系统
  10. ae插件form_四分钟了解全网最受欢迎的10大AE插件
  11. 公司内网openvpn部署,
  12. 探索数藏未来 秦储数字藏品座谈会成功召开
  13. 2018年第九届蓝桥杯真题解析 | 日志统计【Python】
  14. 使用__vmx_vmwrite遇到的问题
  15. WBS 及 WBS字典
  16. 单片机STM32的5个时钟源知识,你不能错过。
  17. c语言中英文字母的符号,C语言中的符号(国外英文资料).doc
  18. WinEdt引用参考文献
  19. Arch Linux 系统迁移
  20. Diem(原Libra)学习笔记

热门文章

  1. ASP.NET中 Calendar(日期控件)的使用
  2. 在Linux server上建立NAS文件服务器
  3. winForm调用HTTP短信接口
  4. 用C#制作新闻阅读器(电脑报2005年3月14日 第10期)
  5. dubbo集群和负载均衡
  6. HTTP状态码和支持的方法
  7. EIGRP 实验2: 邻居关系
  8. rails 如何 支持 bootstrap3
  9. [转]PHP用mysql数据库存储session
  10. CentOS6.4之文本编辑器Vi/Vim