iOS常见的手势
来源:互联网 发布:python无参函数 编辑:程序博客网 时间:2024/05/29 16:29
点击打开链接
#import "RootViewController.h"@interface RootViewController ()@end@implementation RootViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // 创建一个imageView添加手势 UIImageView *imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds]; imageView.image = [UIImage imageNamed:@"text.jpg"]; // UIImageView默认交互是关闭的 imageView.userInteractionEnabled = YES; [self.view addSubview: imageView]; [imageView release]; //////////////////////////////////////////////////////////////// // 以下为每一种类型的手势的添加方法,为避免冲突,每次可以打开一种,验证其效果. //////////////////////////////////////////////////////////////// // 手势识别器这个类,是一个抽象的类 // 自己本身不实现什么具体功能,具体功能都是有其子类完成的 // 轻拍手势// UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTap:)];// // 用几个手指 轻拍// tap.numberOfTouchesRequired = 2;// // 拍几次// tap.numberOfTapsRequired = 1;// // 把首饰添加到要点击的视图上// [imageView addGestureRecognizer:tap];// [tap release]; // 长按手势// UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(actionLongPress:)];// // 最短长按时间// longPress.minimumPressDuration = 1;// // 添加到视图上// [imageView addGestureRecognizer:longPress];// // [longPress release]; // 旋转手势// UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(actionRotation:)];// // 添加到视图上// [imageView addGestureRecognizer:rotation];// [rotation release]; // 捏合手势(缩放扩大手势)// UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(actionPinch:)];// // 直接添加到视图上// [imageView addGestureRecognizer:pinch];// [pinch release]; // 平移手势// UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(actionPan:)];// [imageView addGestureRecognizer:pan];// [pan release]; // 轻扫手势// UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(actionSwipe:)];// // 设置左右扫// swipe.direction = UISwipeGestureRecognizerDirectionLeft;// [imageView addGestureRecognizer:swipe];// [swipe release]; // 边缘轻扫识别器 默认的 你不加他也有 UIScreenEdgePanGestureRecognizer *ScreenEdge = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(actionScreenEdge:)]; // 设置从屏幕边缘 那边去扫 ScreenEdge.edges = UIRectEdgeLeft; [imageView addGestureRecognizer:ScreenEdge]; [ScreenEdge release];}// 长按手势触发的方法- (void)actionLongPress:(UILongPressGestureRecognizer *)longPress{ // 长按 换张图片 UIImageView *imageView = (UIImageView *)longPress.view; imageView.image = [UIImage imageNamed:@"tap.jpg"]; }// 旋转手势触发方法- (void)actionRotation:(UIRotationGestureRecognizer *)rotation{ // transform 形变属性 // 描述一下这个方法 // 第一个参数 传入要制造那个视图的形变属性 // 第二个参数 传入 手势的弧度 rotation.view.transform = CGAffineTransformRotate(rotation.view.transform, rotation.rotation); // 把弧度重置 rotation.rotation = 0;}// 捏合手势- (void)actionPinch:(UIPinchGestureRecognizer *)pinch{ // 形变属性控制 捏合 // 第二个参数 按捏的刻度比例 形变 pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale); // 重置比例 pinch.scale = 1; }// 平移- (void)actionPan:(UIPanGestureRecognizer *)pan{ // 这个点 以手指触摸到屏幕那一刻 即为 0,0点 CGPoint p = [pan translationInView:pan.view]; pan.view.transform = CGAffineTransformTranslate(pan.view.transform, p.x, p.y); // 重置点 让它以为每次都是刚开始触发 [pan setTranslation:CGPointMake(0, 0) inView:pan.view]; NSLog(@"%@", NSStringFromCGPoint(p));}// 轻扫手势- (void)actionSwipe:(UISwipeGestureRecognizer *)swipe{ NSLog(@"左扫了");}- (void)actionTap:(UITapGestureRecognizer *)tap{ NSLog(@"请拍拍");}// 屏幕边缘识别器- (void)actionScreenEdge:(UIScreenEdgePanGestureRecognizer *)screenEdgePan{ // 刚一扫就触发 判断状态 if(screenEdgePan.state == UIGestureRecognizerStateBegan) { NSLog(@"扫出来一次,挺费劲"); }}
1 0
- iOS常见的手势
- IOS常见事件、手势的应用
- iOS 常见手势
- IOS UI中常见的几种手势
- 常见手势的响应事件
- ios手势的综合
- iOS 手势的用法
- iOS的手势控制
- iOS 手势的学习
- iOS的手势
- IOS的手势检测
- iOS -- 基本的手势
- iOS 手势的介绍
- ios的手势的添加
- Ios中手势的利用
- iOS四个方向的手势
- IOS各种手势的使用
- iOS的手势识别模型
- 解决在onCreate()过程中获取View的width和Height为0的4种方法
- 安卓开机流程
- UVa489刽子手的游戏
- iOS之富文本
- SpoolDirectorySource使用及源码分析
- iOS常见的手势
- spring boot 页面获取应用程序路径
- 优先队列
- appStore_审核指南
- 内部类
- 链表
- 第一次写博客
- android 五大布局
- 其它书籍笔记