菜鸟教程小白 发表于 2022-12-12 18:55:06

iphone - 传递触摸手势


                                            <p><p>我正在寻找一种解决方案来帮助“传递”触摸手势。</p>

<p>基本上我有一个菜单,我希望用户能够通过一次连续拖动将项目从菜单拖放到 Canvas 上。</p>

<p>我已经通过平移手势实现了可拖动的图像(我们将这些实例称为 Sprites)。我还可以使用按钮或带有触摸手势的 UIImageView 在 UIView 上的任何位置实例化 Sprite。</p>

<p>但是,目前这需要两次触摸。一个触摸菜单项按钮并释放,创建 Sprite。第二个触摸 Sprite ,允许用户拖动它,然后在他们想要的地方释放它。我想合并这些触摸,以便当用户触摸菜单项时,Sprite 被实例化并且已经在平移手势中,或者有类似影响的东西。</p>

<p>如果有帮助,我已附上视觉描述。任何帮助表示赞赏。谢谢!</p>

<p> <img src="/image/AryjZ.png" alt="enter image description here"/> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>没有办法人为地强制 UIGestureRecognizer 识别传递给不同 View 的触摸。</p>

<p> <a href="http://developer.apple.com/library/IOs/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html#//apple_ref/doc/uid/TP40009541-CH6-SW1" rel="noreferrer noopener nofollow">From the Gesture Recognizer docs:</a> </p>

<blockquote>
<p>Delivery of events initially follows the usual path: from operating
system to the application object to the window object representing the
window in which the touches are occurring. But before sending an event
to the hit-tested view, the window object sends it to the gesture
recognizer attached to that view or to any of that view’s subviews.
Figure 3-1 illustrates this general path, with the numbers indicating
the order in which touches are received.</p>
</blockquote>

<p>图 3-1</p>

<p> <img src="/image/5tD2W.jpg" alt="enter image description here"/> </p>

<p>事件的传递由系统自动发生并传递到适当的 View 。</p>

<p>为了做你想做的事,我将在 subview (包含你的 UIButton 的 View )上实现 UIGestureRecognizer,然后在按下时创建你的 Sprite 对象的实例,并通过使用 subview 的手势识别器来操作该对象。或者,您可以使用 <code>-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)even</code> 自己重新定位对象。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 传递触摸手势,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/8815761/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/8815761/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 传递触摸手势