tags:

views:

52

answers:

1

Hi,

I want to use two views in UIScrollView. In the first view, when I scale down to 50% its size then the second view will show and then the first view will hide then the second view will continue scrolling down. Now my problem is how can I scroll down the second view?

Thanks.

+1  A: 

You can layer as many views (hidden or otherwise) as you like onto a UIScrollView (ie so they will all scroll and be zoomable).

The question is, do you want your second view to be scaled at 1.0 when the first view is scaled at 0.5? You can probably achieve this by setting the transform for the second view to by a 2x scaler. Then catch the zoom event (sorry, don't have the exact name to hand) and if the scale goes down to 0.5 or below, hide the first view and show the second (and vice-versa going the other way, of course).

[edit]

To scale the second view you'd do something like this just once when setting it up:

view2.alpha = 0;
[view2 setTransform:CGAffineTransformMakeScale(2, 2)];

Then later override the zoom event:


-(void) scrollViewDidEndZooming: (UIScrollView*) scrollView 
                       withView: (UIView*) view 
                        atScale: (float) scale
{
  if( scale <= 0.5 and prevScale > 0.5 )
  {
    view1.alpha = 0;
    view2.alpha = 1;
  }
  else
  {
    view1.alpha = 1;
    view2.alpha = 0;
  }
  prevScale = scale;
}

Of course all the usual caveats about untested code apply.

Phil Nash
Thanks. How can I transform the second view, while the first view is scaling? And how the second view will handle the pinch or expand gestures?
sasayins
I'm not near my Mac so can't give you exact code, but you can set the transform property of the view to a 2x scaler affine transform and just keep it like that all the time. Basically the second view would just be hidden until you need to switch it.
Phil Nash
Thanks a lot. If I switch to the second view, can I also make a pinch or expand gesture with that second view?
sasayins