viewForZoomingInScrollView

viewForZoomingInScrollView

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

问题描述

我有一个 UIScrollView ,由 viewForZoomingInScrollView 返回的视图的多个级别的子视图。在缩放期间,我想要一些这些子视图调整大小,其他人不调整大小。无论我尝试,所有的子视图调整大小。在subview的subview我想不调整大小,我设置autoResizesSubviews = NO,也尝试了 contentMode = UIViewContentModeCenter 。我也尝试为 UIViewAutoresizingNone 所涉及的所有视图设置 autoresizingMask 。有什么想法吗?我不能重构subviews的层次结构。

I have a UIScrollView, with several levels of subviews of the view returned by viewForZoomingInScrollView. During zooming, I want some of those subviews to resize, and others to not resize. No matter what I try, all subviews resize. On the superview of the subviews I want to not resize, I've set autoResizesSubviews = NO, and also tried contentMode = UIViewContentModeCenter. I've also tried setting the autoresizingMask for all views involved to UIViewAutoresizingNone. Any thoughts? I can't restructure the hierarchy of subviews.

推荐答案

UIScrollView的缩放视图的子视图通过改变它们的变换,不是通过改变它们的边界等。你的问题的一个简单的解决方案是捕获放大视图上设置的变换,反转它,并将其应用到子视图,取消滚动视图应用的缩放变换。

The subviews of UIScrollView's zooming view are "resized" by changing their transforms, not by changing their bounds, etc. One simple solution to your question is to catch the transform being set on the zooming view, invert it, and apply it to the subviews, canceling out the zooming transform applied by the scroll view.

viewForZoomingInScrollView 返回的视图中,覆盖-setTransform :,然后浏览所有相关子视图,并应用反演变换:

In the view returned by viewForZoomingInScrollView, override -setTransform:, and go through all the subviews in question and apply the inverted transform:

- (void)setTransform:(CGAffineTransform)transform
{
    [super setTransform:transform];

    CGAffineTransform invertedTransform = CGAffineTransformInvert(transform);
    for (UIView *view in subviewsNotToBeResized)
    {
        [view setTransform:invertedTransform];
    }
}

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

08-24 09:17