Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

ios - resize all subview in scrollViewDidZoom

Below is my screen design.

enter image description here.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...