我正试图在屏幕上获取触摸的坐标,以显示弹出菜单
如何在页面视图控制器中使用
我在这做错了什么?
override func touchesBegan(touches: Set<UITouch>,withEvent event: UIEvent?) { if let touch = touches.first { let position = touch.locationInView(view) print(position) } }
解决方法
在PageViewController中,如果要弹出窗口
在viewDidLoad中:
let tap = UITapGestureRecognizer(target: self,action: "showMoreActions:") tap.numberOfTapsRequired = 1 view.addGestureRecognizer(tap)
使页面视图控制器继承UIGestureRecognizerDelegate,然后添加:
func showMoreActions(touch: UITapGestureRecognizer) { let touchPoint = touch.locationInView(self.view) let DynamicView = UIView(frame: CGRectMake(touchPoint.x,touchPoint.y,100,100)) DynamicView.backgroundColor=UIColor.greenColor() DynamicView.layer.cornerRadius=25 DynamicView.layer.borderWidth=2 self.view.addSubview(DynamicView) }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。