resize all subview in scrollViewDidZoom

后端 未结 1 1947
失恋的感觉
失恋的感觉 2020-12-10 23:25

Below is my screen design.

\"enter.

I want Zoom in/out in **mainView*

相关标签:
1条回答
  • 2020-12-11 00:00

    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);
    }
    
    0 讨论(0)
提交回复
热议问题