Moving a UIIMageView outside of a UIScrollView
At the bottom part of my main UIView, I've an UIScr开发者_如何学编程ollView 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
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.
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...
精彩评论