菜鸟教程小白 发表于 2022-12-11 18:10:28

ios - 当我移动触摸点时,如何确定我是否有一个长按的 UIView?


                                            <p><p>我试图弄清楚如何确定我的接触点是否在我有 UIView 作为 subview 的位置。背景是 UIView 本身,我正在将多个其他 UIView 添加到...所以当我长按并在按住触摸的同时更改位置时,我想知道此时是否有 UIView。 </p>

<p>我一直在想,仍然不清楚如何去做,但遇到了<a href="https://stackoverflow.com/questions/17758891/how-can-i-get-the-index-of-sub-uiview-in-the-parent-view" rel="noreferrer noopener nofollow">this</a>这让我想到了获取层次结构的索引并检查它是否大于 1。但是我怎么能在我接触的地方这样做呢?</p>

<p>任何提示或线索将不胜感激。 </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您必须将两个引用存储在两个对象中 <code>myParentView</code> 和 <code>mySubView</code> 现在只需使用此方法..</p>

<pre><code>-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    CGPoint locationPoint = [ locationInView: myParentView];
    UIView* viewYouWishToObtain = ;
    if(mySubView == viewYouWishToObtain){

         //That view is touched
    }else{
      //That view is not touched
}
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 当我移动触摸点时,如何确定我是否有一个长按的 UIView?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40827607/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40827607/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 当我移动触摸点时,如何确定我是否有一个长按的 UIView?