菜鸟教程小白 发表于 2022-12-12 10:16:42

ios - 如何区分用户滑动和点击 Action ?


                                            <p><p>我正在开发一个应用程序,其中我有一个包含 subView 的 View 。
我想跟踪滑动和点击操作,例如单击。</p>

<p>仅当用户在我的 subview 中触摸时才应跟踪操作。当用户点击我想执行一个操作时,当用户滑动我想执行另一个操作。</p>

<p>为了跟踪滑动,我实现了 <code>UIGestureRecognizer</code> 并且工作正常。但我不知道如何跟踪点击选项。请指导我如何实现这一目标。</p>

<p>主要的是,当我点击时,它应该只调用点击 Action ,反之亦然。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您可以使用 <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UITapGestureRecognizer_Class/Reference/Reference.html" rel="noreferrer noopener nofollow"><strong>UITapGestureRecognizer</strong></a>用于点击手势。</p>

<blockquote>
<p>&#34;UITapGestureRecognizer is a concrete subclass of UIGestureRecognizer
that looks for single or multiple taps. For the gesture to be
recognized, the specified number of fingers must tap the view a
specified number of times.&#34;</p>
</blockquote>

<p>此方法包括 <code>numberOfTapsRequired</code>(“要识别的手势的点击次数。”)和 <code>numberOfTouchesRequired</code>(“点击手势所需的手指数”要识别的手势") 属性,您可以在其中准确设置您希望它如何响应用户操作。</p>

<p>在这种情况下,由于您只希望在点击一次时激活它,因此这两个属性的默认设置(都具有默认值 1)应该没问题。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何区分用户滑动和点击 Action ?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/15896802/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/15896802/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何区分用户滑动和点击 Action ?