Swift UITouch 的使用
来源:互联网 发布:网络渗透测试工程师 编辑:程序博客网 时间:2024/06/10 18:31
touch 允许多点触碰
在viewLoad()中
self.view.multipleTouchEnabled = true;
/* override (重写): 方法名、参数、返回值相同。2.子类方法不能缩小父类方法的访问权限 3.子类方法不能抛出比父类方法更多的异常(但子类方法可以不抛出异常)。4.存在于父类和子类之间 5.方法被定义为final不能被重写; overload (重载):参数类型、个数、顺序至少有一个不相同;2.不能重载只有返回值不同的方法名 3.存在于父类和子类、同类中 */
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { for touch :AnyObject in touches { let t : UITouch = touch as! UITouch; //在屏幕上连续拍击两次,背景变为灰色 if (t.tapCount == 2) { self.view.backgroundColor = UIColor.grayColor(); }else if(t.tapCount == 1){ self.view.backgroundColor = UIColor.brownColor(); } print("begin"); } } override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { for touch : AnyObject in touches { let t : UITouch = touch as! UITouch; print(t.locationInView(self.view)); } } override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { //两点触摸时,计算两点之间的距离,以及角度 if touches.count == 2 { //获取触摸点 let frist = (touches as NSSet).allObjects[0] as! UITouch; let second = (touches as NSSet).allObjects[1] as! UITouch; //获取触摸点坐标 let fristPoint = frist.locationInView(self.view); let secondPoint = second.locationInView(self.view); //计算两点之间的距离 let distanceX = fristPoint.x - secondPoint.x; let distanceY = fristPoint.y - secondPoint.y; let distance = sqrt(distanceX * distanceX + distanceY * distanceY); print("两点之间的距离:",distance); //计算两点间的角度 let height = secondPoint.y - fristPoint.y; let width = fristPoint.x - secondPoint.x; let rads = atan(height/width); let degrees = 180.0 * rads * 3.1415; print("两点之间的角度:",degrees); }<pre name="code" class="html">override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) { print("event cancelled====================="); }
}
0 0
- Swift UITouch 的使用
- UITouch 的使用
- UITouch使用
- iOS开发基础 - UITouch的使用
- IOS学习之——UItouch的相关使用
- UITouch 的解析
- UITouch的用法
- Swift版 ScrollView和UITouch事件冲突
- UITouch
- UITouch
- UITouch
- UITouch
- UITouch
- UITouch
- UITouch
- UITouch
- UITouch
- UITouch
- solidthinking inspire 拓扑优化工具问答-转
- JAVA类获取mybatis的mapper进行数据库操作
- 从源码角度解析Handler
- ios 编译openssl支持arm64
- 码神-day7-java
- Swift UITouch 的使用
- TI C6000DSP上TCP/IP协议栈的实现
- c#计算程序的运行时间
- Java-Enumeration
- 矩形覆盖
- ACM--解析HTML--HDOJ 1088--Write a simple HTML Browser--水
- 2016暑假多校合练第一场Multi-University Training Contest 1 1001 Abandoned country
- c#自定义排序方法
- hdu1242 Rescue--BFS