简体   繁体   English

UIScrollView中的两个子视图

[英]Two subviews in UIScrollView

I want to use two views in UIScrollView. 我想在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. 在第一个视图中,当我缩小到其大小的50%时,将显示第二个视图,然后第一个视图将隐藏,然后第二个视图将继续向下滚动。 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). 您可以根据需要在UIScrollView上层叠任意数量的视图(隐藏或其他)(即,它们将全部滚动并可缩放)。

The question is, do you want your second view to be scaled at 1.0 when the first view is scaled at 0.5? 问题是,当第一个视图缩放为0.5时,是否要将第二个视图缩放为1.0? You can probably achieve this by setting the transform for the second view to by a 2x scaler. 您可以通过将第二个视图的转换设置为2x缩放器来实现此目的。 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). 然后捕获缩放事件(对不起,没有确切的名称),如果比例缩小到0.5或以下,则隐藏第一个视图并显示第二个视图(当然,反之亦然) 。

[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: 然后,稍后覆盖zoom事件:


-(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. 当然,所有有关未经测试的代码的通常警告都适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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