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

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

问题描述

以下是我的屏幕设计.

.

我想要放大/缩小**mainView**.主视图宽度 &高度为 300. 要放大/缩小,我已经实现了下面的方法,并且可以很好地使用此方法.

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;
}

到此为止一切都很好.我已经设置了 scroll.minimumZoomScale=1scroll.maximumZoomScale=5.

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

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

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

在放大时间

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

在此过程中 innerView 由于 autoresize 属性而调整大小.但是 Width &innerView 的高度为 100(在放大/缩小时不会改变).

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 ??

最后我想要什么每当 innerView &lblTest 帧改变比我想在 zoom in/out 时间增加/减少 lblTestnumberOfLine .

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

我尝试添加 innerView &lblTest 手动但得到它的宽度 &高度增加超过其父视图(mainView).

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 .

提前致谢.

推荐答案

当您放大滚动视图时,zoomView(在您的情况下为 mainView)不是调整大小,只是在其图层上应用仿射变换 (CALayer).例如,在 1.2 zoomScale 的情况下,它是:[1.2, 0, 0, 1.2, 0, 0].所以它的边界没有改变——只是它的所有内容都被放大/缩小了,它也会影响它的 frame 属性——所以包含的内部视图和标签也不会被调整大小,只是在放大/缩小时渲染 mainView,这就是它们的框架不受影响的原因.

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.

只需在delegate中实现- (void)scrollViewDidZoom:(UIScrollView *)scrollView 并打印出主视图的frame, bounds, layer.affineTransform 看看会发生什么缩放.

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.

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

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天全站免登陆