問題描述
只是在玩 SDK,我想知道 UITouch 事件是否可以在 UIScrollView 中工作.
Just toying with the SDK and I was wondering if possible a UITouch event can work inside a UIScrollView.
我已經(jīng)設(shè)置了一個(gè)處理大型 UIView 的 UIScrollView,在 UIView 內(nèi)部是一個(gè) UIImageView,我設(shè)法讓 UITouch 將 UIImageView 拖到 UIScrollView 之外,但在它內(nèi)部沒有注冊(cè)事件.
I have setup a UIScrollView which handles a large UIView, inside the UIView is a UIImageView, I've managed to get the UITouch to drag the UIImageView outside of the UIScrollView but inside it's not registering the event.
我想我想要完成的是在大 UIView 周圍拖動(dòng) UIImageView 而 UIScrollView 沿著圖像移動(dòng),如果用戶將其拖動(dòng)到 UIImageView 開始拖動(dòng)時(shí)的 POS 之外,如果這有意義嗎?
I suppose what I was trying to accomplish was dragging the UIImageView around the large UIView whilst the UIScrollView moves along the image if the user drags it beyond the POS of when the UIView when the UIImageView began it's dragging, if that makes sense?
非常感謝
推薦答案
(如果我理解正確的話)
(If I understood the question correctly)
UIScrollView 攔截 touchMoved
事件,如果啟用滾動(dòng),則不會(huì)將它們傳播到其內(nèi)容.因此,為了在我的應(yīng)用程序中拖動(dòng) UIScrollView 內(nèi)容,我做了以下技巧:
UIScrollView intercepts touchMoved
events and does not propagate them to its contents if scrolling is enabled. So to do the dragging in the UIScrollView contents in my app I did the following trick:
touchesBegan:檢查您是否觸摸了可拖動(dòng)"區(qū)域.如果是 - 禁用 UIScrollView 中的滾動(dòng).
touchesBegan: Check if you touch the "draggable" region. If YES - disable scrolling in UIScrollView.
touchesMoved:現(xiàn)在,當(dāng)滾動(dòng)被禁用時(shí),您的內(nèi)容視圖會(huì)收到此事件,您可以相應(yīng)地移動(dòng)可拖動(dòng)的 UIImageView.
touchesMoved: Now as scrolling is disabled your contents view receives this event and you can move your draggable UIImageView accordingly.
touchesEnded:在 UIScrolliew 中重新啟用滾動(dòng).
touchesEnded: Reenable scrolling in UIScrolliew.
如果您想將視圖拖到可見的 UIScrollView 區(qū)域之外,您可能還需要手動(dòng)檢查您是否靠近邊界并手動(dòng)調(diào)整內(nèi)容偏移量(我自己沒有嘗試過,但我認(rèn)為它應(yīng)該可以工作).
If you want to drag the view outside of the visible UIScrollView area you may also need to check manually if you're near the boundaries and manually adjust contents offset (I didn't try this myself but I think it should work).
這篇關(guān)于在 UIScrollView 中使用 UITouch的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!