ios中的手势
来源:互联网 发布:上海地铁客流量数据 编辑:程序博客网 时间:2024/06/05 00:08
手势很简单,前面是准备工作,重点在下面// 准备工作@interface RootViewController ()@property (nonatomic ,retain) UIImageView *amyImageView;@property (nonatomic, retain) UIImageView *bmyImageView;//记录开始的点@property (nonatomic, assign) CGPoint startPoint;@end@implementation RootViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //创建两个imageView self.amyImageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 200, 200, 200)]; self.amyImageView.backgroundColor = [UIColor orangeColor]; [self.view addSubview:self.amyImageView]; self.amyImageView.userInteractionEnabled = YES; self.bmyImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 20, 375, 100)]; self.bmyImageView.backgroundColor = [UIColor orangeColor]; [self.view addSubview:self.bmyImageView];/ ********** 1. 轻拍 手势 以及详细的设置 **************// 一个 UITapGestureRecognizer 对象只能添加到一个view 上//// UITapGestureRecognizer 是个抽象类,主要是提供一些通用的属性和方法,一般我们不用抽象类来创建对象,而是它的子类们// UITapGestureRecognizer *tapG = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];//// 将手势 添加到 imageV 上// [self.amyImageView addGestureRecognizer:tapG];//// imageView 和 lable 的用户交互默认为关闭 需要打开// self.amyImageView.userInteractionEnabled = YES;//// 轻拍次数// tapG.numberOfTapsRequired = 1;//// 需要多少个手指// tapG.numberOfTouchesRequired = 1;// [tapG release];//// ***************// UITapGestureRecognizer *tapG1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];// // 将手势 添加到 imageV 上// [self.bmyImageView addGestureRecognizer:tapG1];// // imageView 和 lable 的用户交互默认为关闭 需要打开// self.bmyImageView.userInteractionEnabled = YES;// // 轻拍次数// tapG1.numberOfTapsRequired = 1;// // 需要多少个手指// tapG1.numberOfTouchesRequired = 1;// [tapG1 release];//// self.amyImageView.tag = 1000;// self.bmyImageView.tag = 10/ ********** 2. 长按 手势 **********************// UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(LongAction:)];// [self.amyImageView addGestureRecognizer:longPress];// [longPress releas//********* 3. 旋转 手势 *************************// UIRotationGestureRecognizer *rotaGR = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotaGRAction:)];// [self.amyImageView addGestureRecognizer:rotaGR];// [rotaGR release];/ ********** 4. 捏合 手势 ************************* UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)]; [self.amyImageView addGestureRecognizer:pinch]; [pinch release];}// 下面是:** 手势添加后执行的方法 ** // 4 . 捏合 的方法- (void)pinchAction:(UIPinchGestureRecognizer *)sender { self.amyImageView.transform = CGAffineTransformMakeScale(sender.scale, sender.scale);}// 3. 旋转方法//- (void)rotaGRAction:(UIRotationGestureRecognizer *)sender {//// transform 属性是view 的属性,是做图形变换的,也叫2d仿射变换,内部实现是用矩阵公式来计算的// self.amyImageView.transform = CGAffineTransformMakeRotation(sender.rotation);////}//// 2. 长按 手势动作 长按 移动view 的位置//- (void)LongAction:(UILongPressGestureRecognizer *)sender {// NSLog(@"长按 手势");// if (sender.state == UIGestureRecognizerStateBegan) {// NSLog(@"长按 开始");// // 获取 手指触摸屏幕的点// self.startPoint = [sender locationInView:self.amyImageView];//// NSLog(@"point = %@", NSStringFromCGPoint(self.startPoint));//// } else if (sender.state == UIGestureRecognizerStateChanged) {// NSLog(@"长按 中");// // 获取 手指触摸屏幕的点// CGPoint point = [sender locationInView:self.amyImageView];// CGFloat dx = point.x - self.startPoint.x;// CGFloat dy = point.y - self.startPoint.y;//// NSLog(@"point = %@", NSStringFromCGPoint(point));//// 改变中心点的坐标 原来坐标 + 移动距离// self.amyImageView.center = CGPointMake(self.amyImageView.center.x + dx, self.amyImageView.center.y + dy);// } else if (sender.state == UIGestureRecognizerStateEnded) {//// NSLog(@"长按 结束");// }//}//// 1 . 轻拍手势 的动作//- (void)tapAction:(UITapGestureRecognizer *)tap {////// ***** 重要的属性 tap.view//// 强转// UIImageView *imageView = (UIImageView *)tap.view.tag;// if (imageView.tag == 1000) {// self.amyImageView.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];// } else {// NSLog(@"aaaaaa");// }//}
1 0
- IOS中的六大手势
- iOS中的手势
- IOS中的手势详解
- iOS中的七大手势
- iOS中的各种手势
- IOS 中的手势
- ios中的手势
- iOS中的手势详解
- ios中的6种手势
- ios开发中的手势添加
- iOS中的事件,手势识别
- iOS开发中的手势添加
- iOS开发中的手势总结
- iOS开发中的手势触发
- 关于iOS中的手势识别
- 总结iOS开发中的手势识别
- 谈谈iOS中的手势及触摸
- iOS中的触摸事件和手势处理
- leetcode -- Minimum Height Trees -- 关于graph的,重点
- eclipse jetty插件的安装
- Android启动页面的正确打开方式
- ORACLE11g R2 DG FOR OEL7.1 安装实施
- ios 第二课 类的初始化
- ios中的手势
- 最好的Python机器学习库
- C语言预处理及特殊函数介绍(extern/exit/atexit/volatile/static/calloc/realloc等)PART ONE
- [笔记] 大型网站技术架构——核心原理与案例分析 [三]
- FireFox 之 event is not defined
- 10G(82599EB) 网卡测试优化(总)
- 欧冠16强抽签概率计算器
- 获取焦点、监听软键盘、关闭软键盘、适应ListView控件
- Python 基础语法(一)