Sunday, March 27, 2011

Removing views from UIScrollView

I have two UIScrollViews that I move images between. The user can drag and forth between the scroll views. I am trying to animate the movement of the image from one scroll view to another. In -touchesMoved (handled in my UIViewController which has two custom UIScrollViews that intercept touch and sends to my UIViewController), I am trying to set the "center" of my UIImageView that is being moved. As it is moved, the image gets hidden behind the UIScrollView and not visible. How do I make it appear on top of the UIScrollView? I am able to handle the -touchesEnded properly by animating in the destination scroll view.

I am also confused about -convertPoint:fromView: usage in the iPhone Programming Guide (See Chapter 3, Event Handling). If the touch coordinates are in window coordinates, to change my view (UIImageView inside a UIScrollView which is inside a UIView and inside a window) center don't I have to use -convertPoint:toView:, i.e.,

imageView.center = [self.view.window convertPoint:currentTouchPosition toView:imageView];

What am I missing?

From stackoverflow
  • You can use the method - (void)bringSubviewToFront:(UIView *)view for making the image view the front most view.

    Johan

  • Hi,

    That did not seem to work. I see the above API used in SiesmicXML (Apple reference) trying to keep the earthquake image above everything in a tableview Cell. Somehow it did not work for me.

    Thanks mohan

  • It depends on how you structured your views. If both scrollviews and the imageview are at the same level, it should work. If the imageview is a subview of one of the scrollviews, you can try bringing the scrollview to the front. That way also the imageview will be drawn over the other scrollview.

    Johan

  • Hi,

    I have a View Controller with two ScrollViews. Images are added as subviews. ScrollViews are already in the front. I tried bringing scrollview to the front and also imageview of the scrollview to the front. But somehow when i drag, the center of the image goes over my other scrollview2 which i also tried sending back. But does not seem to work. Here is what i do, in TouchesMove (inside a ViewController)

    view= [[scrollView1 subviews] objectAtIndex:currentImageIndex];

    [self.view bringSubviewToFront:scrollView1];

    [scrollView1 bringSubviewToFront:view];

    [self.view sendSubviewToBack:scrollView2];

    scrollView1 and scrollView2 are two scrollviews that are part of the ViewController's view. Does this make sense ?

    thanks mohan

0 comments:

Post a Comment