开发者

Two subviews in UIScrollView

I want to use two views in UIScrollView. In the first view, when I scale down to 50% its siz开发者_运维知识库e 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜