如何在一個UIWindow或UIView的獲得觸摸位置沒有uigesturerecognizer, 目的是在極短的延遲得到觸摸位置作爲調度員可延緩觸摸點火事件IOS觸摸位置,而不uigesturerecognizer
0
A
回答
0
您需要繼承UIView
和覆蓋UIResponder
(超類UIView
)方法touchesBegan(_:with:)
。請參閱方法here的文檔。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
// Get the touch location in THIS VIEW's coordinate system:
let locationInThisView = touch.location(in: self)
// Get the touch location in the WINDOW's coordinate system
let locationInWindow = touch.location(in: nil)
}
}
此外,請確保您的觀點有物業isUserInteractionEnabled
設置爲true
。
0
覆蓋以下方法在您的UIView子類中。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let point = touches.first?.location(in: self)
print("location: ", point ?? CGPoint.zero)
}
+0
當我重寫touchesBegan時,我仍然需要等到調度員觸發touchesBegan事件後,在我的個人測試中,它會以50Hz的頻率被觸發,並有一些延遲,但我想要得到100Hz的低延遲 – user818117
相關問題
- 1. 怪異IOS觸摸事件與UIGestureRecognizer
- 2. UIGestureRecognizer觸摸移動UIView
- 3. 觸摸位置
- 4. 觸摸位置CCLayer
- 5. UIResponder vs UIGestureRecognizer觸摸事件響應
- 6. UIGestureRecognizer手柄觸摸在UITableView的
- 7. Siri遠程觸摸位置?
- 8. UIView觸摸位置座標
- 9. 識別觸摸位置
- 10. UIButton TouchUpInside觸摸位置
- 11. UIPinchGestureRecognizer的觸摸位置
- 12. 當前觸摸位置
- 13. GLKit檢測觸摸位置
- 14. 觸摸位置高亮
- 15. 獲取觸摸位置scrollView
- 16. UIGestureRecognizer - 獲取對觸摸的UIViewController的引用,而不是其視圖?
- 17. 如何觸發UISlider的UIControlEventValueChanged而不觸摸iOS中的UISlider?
- 18. 獲取位於觸摸位置的uiview
- 19. 如何重置NSTimer的觸摸,觸摸移動在ios
- 20. SKShapeNode與SKAction觸摸結束時,從觸摸位置移動
- 21. 如何獲得觸摸的觸摸位置開始功能
- 22. 使用位置查找手勢觸摸的座標觸摸
- 23. 添加圖像在觸摸位置的Android觸摸佈局
- 24. 位置固定和webkit溢出觸摸問題ios 7
- 25. 獲取觸摸位置谷歌地圖iOS
- 26. 觸摸IOS畫線
- 27. Monogame觸摸位置座標與觸摸屏分辨率不匹配
- 28. 自定義TouchDevice觸發不正確位置的觸摸事件
- 29. UIGestureRecognizer在視圖superview上設置觸摸的最小數量而不是視圖本身?
- 30. 如何測試觸摸屏(而不是「觸摸功能」)?
當我重寫的touchesBegan我還需要等到調度觸發的touchesBegan事件,在我個人的測試中,它與50Hz的發射,具有一定的延遲,但我想要得到它的100Hz,低延遲 – user818117
據據我所知,iOS SDK不提供更快的速度。也許如果你改爲「UIWindow」的子類(視圖層次結構的根對象),它會稍微調用一些? –
也許重寫'UIApplication.sendEvent()'?想不到別的。無論哪種方式,'touchesBegan(...)的速度足夠快,以至於人類用戶的交互感覺很自然。我不知道你的應用程序試圖做什麼,需要在這種實時條件下檢測水龍頭, –