tags:

views:

219

answers:

2

Hello,

At the bottom part of my main UIView, I've an UIScrollView with an UIImageView inside.

I'd like to move the UIImageView from the UIScrollView to the top part of my UIView.

I'm able to move my UIImageView inside the UIScrollView, but outside, I can't. The UIImageView remains in the UIScrollView, it's parent.

Any idea?

Thanks in advance for any help.

Best regards,

Alx

A: 

As I understand, you add in code UIImageView as subview of UIScrollView, but later can't do reverse operation.

If so, in your UIViewController use something like:

[yourImageView removeFromSuperview];
[self.view addSubview:yourImageView];

If not, add more details to your question...

kpower
It's `-removeFromSuperview`, not `-removeFromSuperView`...
chpwn
The thing is I want to drag my UIImageView from a UIScrollView to my main UIView.So, I've to remove it from the UIScrollView and then add it to the main view, as you said. I do that in the TouchesBegan method.But it's not enough.Because when I'm dragging the image, in the TouchesMoved method I'm doing what I think I should do to move the image, but the move is constraint to the scrollview.I can't understand what I've to do to move the image into the main view. The image stays in the scrollview.
Alx
Hmm... Your UIImageView is not simply on UIScrollView (as it's subview) - it is a subview of scrollview's contentView. That's why, I think, you can't move image outside from scrollview. And the only solution I can suggest is something like this: on touchesBegan make image as main view's subview (remove from scrollview) and proceed with touchesMoved with main view.
kpower
+1  A: 

Don't get fooled by the analogy of the UI. The views aren't actually physical objects that can be easily picked up and moved from location to location. We create the illusion of physical objects with code that has nothing to do with apparent motion of the illusion.

To do what you want will take some work.

Views only draw themselves within their super views. It's frame is defined by its position in the superview. Once the frame is defined as being outside the super view, it no longer draws itself and it disappears from the UI. That is why you just can't drag the UIImage anywhere you want.

What you will have to do is create a transparent overview that lays over both the scrollview and the target view. When the user initiates the drag, you will have to remove the UIImageView from the scroll view and add it to the overview (alternatively, hide the scrollview UIImageView and create a duplicate in the overview). The UIImage will then draw itself in the overview which will create the illusion that it being dragged out of the scroll view. Then you reverse the possess at the target view.

You probably want to rethink your design at least for the iPhone. It is very difficult for users to drag items around the small screen especially if they screen itself has to scroll.

TechZen