我正试图在屏幕上获取触摸的坐标,以显示弹出菜单
如何在页面视图控制器中使用
我在这做错了什么?
override func touchesBegan(touches: Set, withEvent event: UIEvent?) { if let touch = touches.first { let position = touch.locationInView(view) print(position) } }
user3182143.. 14
在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) }
带TouchEvent的UIPageViewController
在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) }
带TouchEvent的UIPageViewController