問題描述
我制作了一個程序,其中包含可以拖動以在屏幕上移動的圖片.我也使用了 UIScrollView,因為空間比窗口大.我將 UIView 子類化為圖片視圖,以在此類中顯示圖片并處理觸摸.圖片視圖作為子視圖添加到滾動視圖.但現(xiàn)在我有一個問題:當我拖動圖片時,scrollView 與圖片一起移動.我想知道是否有辦法消耗圖片類中的觸摸以防止它們傳遞給超級視圖.
I've made a program which contains pictures that can be dragged to move on the screen. also I used UIScrollView since the space is larger than the window. I subclassed UIView as a pictures view to display the picture and handle touches in this class. picture views are added as subviews to the scrollView. but now I have a problem: when I drag the picture, the scrollView moves together with the picture. I'm wondering if there is a way to consume the touches in the picture class to prevent them from passing to superview.
推薦答案
你應(yīng)該把你的代碼放在 UIView 的 "touchesMoved:withEvent:" 方法中.如果你的 View 會自己處理這個事件,那么它不應(yīng)該冒泡到 superview
You should to put your code in "touchesMoved:withEvent:" method of your UIView. If your View will handle this event by yourself, then it should not bubble to superview
這篇關(guān)于如何防止觸摸事件傳遞給 UIView 的超級視圖?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!