简体   繁体   English

长按时手指的 swift 得到 position

[英]swift get position of finger when is pressed longer

I have a scrollview and would like to get the exact position of the finger when the user presses the screen longer.我有一个滚动视图,想在用户长按屏幕时获得手指的确切 position。 Or if that's possible just get the position of the finger in a scrollview when the finger is moving.或者,如果可能的话,当手指移动时,只需在滚动视图中获取手指的 position。

So far I've tried using a LongGestureRecognizer.到目前为止,我已经尝试过使用 LongGestureRecognizer。 Here is my code, it all works, but I still need the exact position of the finger.这是我的代码,一切正常,但我仍然需要手指的确切 position。 Here how I created the Scrollview and the GestureRecognizer.这里我是如何创建 Scrollview 和 GestureRecognizer 的。

    testScroll = UIScrollView(frame: CGRect(x: 0, y: 0, width: width, height: height))
    self.view.addSubview(testScroll)
    testScroll.contentSize = CGSize(width: width, height: height*1.25)
    testScroll.delegate = self
    
    testREc = UILongPressGestureRecognizer(target: self, action: #selector(testprint(sender:)))
    testScroll.addGestureRecognizer(testREc)

if there is a possibility to get the position this way, or exactly via the (testprint func), it would be helpful for me如果有可能以这种方式或完全通过(testprint func)获得 position,这对我会有帮助

If you have any tips, I would appreciate your help.如果您有任何提示,我将不胜感激。

Set the delegate of your UILongPressGestureRecognizer and implement gestureRecognizerShouldBegin() .设置您的UILongPressGestureRecognizerdelegate并实现gestureRecognizerShouldBegin()

There you can get the touch location that triggered the long press.在那里您可以获得触发长按的触摸位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM