菜鸟教程小白 发表于 2022-12-11 19:20:16

ios - 如何在表格 View 中访问手指位置/移动信息?


                                            <p><p>所以我想要做的是让我的表格 View 中的每个单元格都能够向左或向右滑动。如果我可以捕获手指位置/翻译,我可以更改内容的 xanchor 和 bingo bango,但我很难弄清楚。如果有人可以提供帮助,那就太好了</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您可以查看有关 <strong>UISwipeGestureRecognizer</strong> 的苹果文档,默认方向是右,也可以探索此功能 <strong>UISwipeGestureRecognizerDirection</strong> 它返回您的方向是右,左,上,或底部。这里是演示</p>

<pre><code>var swipeRight = UISwipeGestureRecognizer(target: self, action: &#34;respondToSwipeGesture:&#34;)
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
self.view.addGestureRecognizer(swipeRight)

var swipeDown = UISwipeGestureRecognizer(target: self, action: &#34;respondToSwipeGesture:&#34;)
swipeDown.direction = UISwipeGestureRecognizerDirection.Down
self.view.addGestureRecognizer(swipeDown)

func respondToSwipeGesture(gesture: UIGestureRecognizer) {

if let swipeGesture = gesture as? UISwipeGestureRecognizer {


    switch swipeGesture.direction {
      case UISwipeGestureRecognizerDirection.Right:
            print(&#34;Swiped right&#34;)
      case UISwipeGestureRecognizerDirection.Down:
            print(&#34;Swiped down&#34;)
      case UISwipeGestureRecognizerDirection.Left:
            print(&#34;Swiped left&#34;)
      case UISwipeGestureRecognizerDirection.Up:
            print(&#34;Swiped up&#34;)
      default:
            break
    }
}
</code></pre>

<p>}</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何在表格 View 中访问手指位置/移动信息?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/47425929/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/47425929/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何在表格 View 中访问手指位置/移动信息?