touches,motion触摸事件响应
2015-10-15 22:37
274 查看
//触摸事件响应需要重写方法 1 // 触摸时触发该方法(消息发送) - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self.rootView.touchView];//locationInView:得到当前点击下在指定视图中位置的坐标 NSLog(@"触摸开始:%.2f,%.2f",point.x,point.y); } //但触摸移动时触发该事件 - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; CGPoint point1 = [touch locationInView:self.rootView.touchView]; CGPoint point2 = [touch previousLocationInView:self.rootView.touchView];//previouslocationInView:得到当前点的前一个点在指定视图中位置的坐标 } // 触摸结束时触发该方法(消息发送) - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ NSLog(@"触摸结束"); } //发生其他情况,如来电话或意外退出时,执行该方法 - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ }
//手机摇一摇实现要重写方法 1 //开始时调用 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{ NSLog(@"摇一摇开始"); } //结束时调用 - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{ NSLog(@"摇一摇结束"); } //意外情况调用 - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{ NSLog(@"意外退出"); }
相关文章推荐
- laravel md5+salt 密码
- windows 10 edge浏览器去广告
- Visual Studio 2013开发MFC程序对Excel 2010进行写操作(下)
- Android Wear来袭,极客学院全球首发破解可穿戴系统系列课程
- android wear与手机通信发送asset失败问题
- Linux Shell
- MySQL中ROUND和TRUNCATE的区别
- java核心技术之IO流(三)FileReader和FileWriter
- iOS之Cocoa大招KVC键值编码
- Ubuntu Unity 桌面快捷键切换窗口技巧
- [每日一答] [20151015] pandas中的isin函数详解
- JPanel 中的 KeyListener 无效
- 负载均衡(load balance)
- linux ext4无法使用超过16T磁盘的解决办法
- leetcode 29:Divide Two Integers
- 修复BootstrapValidator重复提交的bug
- C语言入门----字符
- Linux正则表达式基础
- AppleWatch开发教程之Watch应用对象新增内容介绍以及编写运行代码
- zabbix监控tomcat(2)