菜鸟教程小白 发表于 2022-12-12 13:14:01

ios - 捕获组合的按钮按下和平移手势


                                            <p><p>我需要在 iOS 上捕获以下触摸事件并对其进行解释:</p>

<ol>
<li><code>UIButton</code> 内的手指触地(保持向下)</li>
<li>手指 B 在屏幕其他位置执行平移手势,提供连续回调。 (我打算使用 <code>UIPanGestureRecognizer</code> 来实现这个功能)。</li>
<li>在同一个 <code>UIButton</code></li> 内进行手指修饰
</ol>

<p>本质上,按住 <code>UIButton</code> 会使应用程序进入一种特殊模式,该模式仅在按住按钮时持续。在此期间执行的平移手势与未按下按钮时执行的操作不同。</p>

<p>到目前为止我已经尝试过:</p>

<ul>
<li>在我的 <code>UIViewController</code> 子类中将 <code>UIButton</code> Touch Down 和 Touch Up Inside 连接到 <code>IBActions</code>。我也有
<ul>
<li>遇到的问题:当按下按钮时另一个手指在屏幕上发生另一个手势时,不会调用 Touch Up Inside 操作。这是因为原来的触摸被取消了。</li>
</ul></li>
<li>将 <code>UITapGestureRecognizer</code> 附加到 <code>UIButton</code>
<ul>
<li>遇到的问题:这只在手指离开屏幕时触发,因此不能在按下按钮时将应用置于特殊模式。</li>
</ul></li>
</ul>

<p>我需要使用 <code>UIButton</code> 而不是 <code>UIView</code> 以便按钮在按下时具有正确的突出显示行为。</p>

<p>鉴于我目前遇到的问题,最好的整体方法是什么?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在“按钮”上使用具有较短 minimumPressDuration 的 UILongPressGestureRecognizer
<a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UILongPressGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UILongPressGestureRecognizer" rel="noreferrer noopener nofollow">http://developer.apple.com/library/ios/#documentation/uikit/reference/UILongPressGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UILongPressGestureRecognizer</a> </p>

<p>重要的是使用手势识别器委托(delegate)来确保gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:为这些识别器返回YES。然后,当您的 UIPanGestureRecognizer 调用事件处理程序时,您可以检查 UILongPressGestureRecognizer 的状态,如果未按下按钮,则忽略平移手势。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 捕获组合的按钮按下和平移手势,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/17968966/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/17968966/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 捕获组合的按钮按下和平移手势