菜鸟教程小白 发表于 2022-12-13 12:11:40

iphone - touchesMoved 在没有 touchesBegan 的情况下调用


                                            <p><p>我在一个容器中有许多自定义 UIView,我会在用户移动它们后对其进行动画处理。为了跟踪他们的移动,我使用 <code>touchesBegan:</code> 获取当前位置,并使用 <code>touchesMoved:</code> 更新位置。</p>

<p>有时,特别是如果我最近移动了一个 View (并且它可能仍在动画回其原始位置),如果我开始拖动另一个 View ,则不会调用 <code>touchesBegan:</code> 选择器,但 <code>touchesMoved:</code> 和 <code>touchesEnded:</code> 会。如何在不首先在 View 上调用 <code>touchesBegan:</code> 的情况下调用 <code>touchesMoved:</code> 和 <code>touchesEnded:</code>?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我发现我的应用存在类似问题。当我为另一个 View 设置动画时,如果我快速触摸第一个 View 并开始滑动,则不会发生 touchesBegan 事件,但一旦第一个 View 消失,我就会开始获取 touchesMoved。</p>

<p>根据这个答案,<a href="https://stackoverflow.com/questions/8433483/app-starts-ignores-user-interaction-events-when-i-call-animatewithdurationdelay" rel="noreferrer noopener nofollow">app starts ignores user interaction events when i call animateWithDuration:delay:options:animations:completion:</a> ,用户交互事件在制作动画时会被忽略,我认为这与我们所看到的一致。尝试使用 <code>UIViewAnimationOptionAllowUserInteraction</code> 选项或 <code>userInteractionEnabled</code> 属性;这应该允许事件按您的要求通过。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - touchesMoved 在没有 touchesBegan 的情况下调用,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/9676545/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/9676545/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - touchesMoved 在没有 touchesBegan 的情况下调用