简体   繁体   中英

Two subviews in UIScrollView

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM