我在AppKit(Getting Mouse Coordinates in Swift)中看到了类似的问题,但它在Catalyst中不起作用,因为NSViewController不可用。如何获取Mac Catalyst中鼠标的坐标?
NSViewController
snvhrwxg1#
您可以将UIHoverGestureRecognizer添加到您的UIView:
let hoverGestureRecognizer = UIHoverGestureRecognizer(target: nil, action: nil) addGestureRecognizer(hoverGestureRecognizer)
字符串然后,您可以通过以下方式从这个手势识别器中检索鼠标指针的坐标:
public var pointerPosition: CGPoint? { guard (hoverGestureRecognizer.state == .began) || (hoverGestureRecognizer.state == .changed) else { return nil } return hoverGestureRecognizer.location(in: self) }
型
1条答案
按热度按时间snvhrwxg1#
您可以将UIHoverGestureRecognizer添加到您的UIView:
字符串
然后,您可以通过以下方式从这个手势识别器中检索鼠标指针的坐标:
型