Drag a UIView without disabling its child iPhone / iPad controls

I have a UIView control (white rectangle in the image)

enter image description here

Alternatively, I can drag this control ...

enter image description here

And when I click the button, I load the subview, which is another that I created, and I placed random controls in it to illustrate my point ...

enter image description here

If you are interested in knowing how I placed this nib file in this UIView control, check out this question. I do not want you to read it in order to understand my question.

In any case, the problem when loading this nib file is that I can no longer drag the top UIView. Because of this, I changed:

enter image description here

for

enter image description here

in UIView a preview. In other words, the UIView of the nib file that I put in the UIView that has a white background.

and when I did this, I managed to drag the control, but the controls inside the view no longer work. I also tried putting the touchhesMoved method in a subview instead, but when I do this, the application behaves strangely. In addition, the purpose of placing the nib file in the UIView control was to avoid repeating the same drag and drop function across multiple nib files.

I really need to create an application, such as a Power Point presentation, and I need to change the slide since the user will copy the UIView, and if its cords are less than x, for example, I load the next slide (nib file) in that uiview. Maybe there is an easier way to do what I need, but if I get it drag and drop to work, I am done because I just need to do this function only once.

+4
source share
1 answer

You must leave the UserInteractionEnabled flag enabled for your subview if you want it to respond to events.

One way to achieve this would be to drag and drop using UIGestureRecognizer.

UIPanGestureRecognizer is perfect for this ( Apple's UIGestureRecognizer )

Basically, you have to attach the gesturerecognizer to the view you want to pan, then adjust its position in the callbacks it calls.

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; panGesture.minimumNumberOfTouches = 1; [draggableSubview addGestureRecognizer:panGesture]; [panGesture release]; 

Then, in the handlePanGesture method, you find out how far the user has started using the translInView method of the resolver that he passed, and translate the view accordingly.

+1
source

All Articles