简体   繁体   中英

Dragging a subview of a view to its parent view

I've been searching for the solution for hours. While I can find similar questions, I didn't get the answer. Please help me with this. Here is the situation.

I'm developing an iPad application. I have a custom UIControl (subclass of UIControl) object C within a UIScrollView B which is within the root view A. So the parent-child relationship is like this: A -> B -> C. What I want to do is to drag my custom UIControl C to the root view A. Here is what I did.

Because C is a UIControl, I registered UIControlEventTouchDown and UIControlEventTouchDragInside events to it to track the finger movement. However, the registered methods got triggered only inside C's frame. When my finger touches inside the frame, it works. When I drag it outside C's frame to B and then A, I lost the finger movement event. I wonder what's the correct way to do this.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIControl_Class/Reference/Reference.html

The UIControlEventTouchDragInside will only notice a drag event inside the bounds of the View. You need to also add a UIControlEventTouchDragOutside to the C View, or you can be notified of all touches and find out where the touch is on the X,Y and see if the coordinate of the touch is inside your C View and then do something with it when the touches end and during the touches dragged.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM