调整scrollViewDidZoom中的所有子视图的大小 [英] resize all subview in scrollViewDidZoom

查看:166
本文介绍了调整scrollViewDidZoom中的所有子视图的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的屏幕设计。





我希望放大/缩小** mainView **。 mainView宽度和宽度高度为300。要放大/缩小,我实现了以下方法,并且此方法正常工作。

   - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView 
{
return mainView;
}

一切都很好。我设置了 scroll.minimumZoomScale = 1 scroll.maximumZoomScale = 5



在放大时间 mainView帧增加取决于** scrollView.zoomScale ** 我检查了 - (void)scrollViewDidZoom :(UIScrollView *)scrollView 在此方法中。



在放大时间

  **如果我得到scrollView.zoomScale = 2而不是mainView Width&如果我得到scrollView.zoomScale = 3而不是mainView Width&则高度变为600 
高度变为900 **

在此过程中 innerView 由于autoresize属性调整大小。但是宽度和宽度innerView的高度为100(放大/缩小时不改变)。



我们可以根据规模改变吗?



最后我想要的是每当 innerView & lblTest 框架更改比我想要增加/减少 numberOfLine lblTest at 放大/缩小时间。



我试图添加 innerView & lblTest 手动但问题是它的宽度和宽度高度增加超过其superview(mainView)。



真的很感激如果有人知道如何存档。



先谢谢。

解决方案

当您放大滚动视图时, zoomView 你的案例中的mainView 没有调整大小,只是在它的图层上应用仿射变换( CALayer )。例如,在1.2 zoomScale的情况下,它是: [1.2,0,0,1.2,0,0]
所以它的界限没有改变 - 只是它的所有内容按比例放大/缩小,它也会影响它的 frame 属性 - 所以也不包含内部视图和标签将被调整大小,只是在渲染mainView时按比例放大/缩小,这就是为什么它们的帧不受影响。



只需实现 - (void)scrollViewDidZoom :(UIScrollView *)scrollView 在委托中打印出主视图的框架,边界,layer.affineTransform 以查看缩放时会发生什么。 / p>

要制作你想要的东西,你必须根据 zoomScale 调整标签:

   - (void)scrollViewDidZoom:(UIScrollView *)scrollView {
float zoomScale = scrollView.zoomScale;
self.label.bounds = CGRectMake(0,0,100 * zoomScale,100 * zoomScale); //假设标签的原始大小为{100,100}
self.label.layer.affineTransform = CGAffineTransformMakeScale(1.0 / zoomScale,1.0 / zoomScale);
}


Below is my screen design.

.

I want Zoom in/out in **mainView**. mainView Width & Height is 300. To Zoom in/out i have implement the below method and its working fine with this.

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return mainView;
}

Everything is fine up to this. I have set scroll.minimumZoomScale=1 and scroll.maximumZoomScale=5.

During Zoom in time mainView Frame increase depend on **scrollView.zoomScale**and i have check - (void)scrollViewDidZoom:(UIScrollView *)scrollView in this method.

At Zoom in time

**if i get scrollView.zoomScale=2 than mainView Width & height become 600
if i get scrollView.zoomScale=3 than mainView Width & height become 900**

During this process innerView resize due to autoresize property.But Width & Height of innerView is 100 (not change at zoom in/out time).

Can we change this according to scale ??

Finally what i want that Whenever innerView & lblTest frame change than i want to increase/decrease the numberOfLine of lblTest at zoom in/outtime.

I have tried to add innerView & lblTest manually but getting the issue that its Width & Height increase more than its superview (mainView).

Really appreciated If any know how to archive this .

Thanks in Advance.

解决方案

When you are zooming in the scroll view, the zoomView (mainView in your case) is not resized, just an affine transformation applied on it's layer (CALayer). For example in case of 1.2 zoomScale it is :[1.2, 0, 0, 1.2, 0, 0]. So it's bounds is not changed - just all of it's content scaled up/down, it also affects it's frame property - so nor the contained inner view, and label will be resized, just scaled up/down when rendering the mainView, this is why their frame is unaffected.

Just implement - (void)scrollViewDidZoom:(UIScrollView *)scrollView in the delegate and print out the main view's frame, bounds, layer.affineTransform to see what happens on zooming.

To make what you want you have to adjust the label according the zoomScale:

- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
    float zoomScale = scrollView.zoomScale;
    self.label.bounds = CGRectMake(0, 0, 100*zoomScale, 100*zoomScale); // supposing that label's original size is {100, 100}
    self.label.layer.affineTransform = CGAffineTransformMakeScale(1.0/zoomScale, 1.0/zoomScale);
}

这篇关于调整scrollViewDidZoom中的所有子视图的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆