UIScrollView缩放后重绘子视图

我有一个UIScrollView与一个孩子UIView(CATiledLayer) – 那么我有一个更多的子视图的视图(其中一些是UITextViews)

放大后的一切都是模糊的。

我已经阅读了关于这个主题的各种文章,他们似乎都表明,我必须处理scrollViewDidEndZooming然后“做一些变换的东西,混乱框架和调整内容偏移量”。 请有人能让我摆脱苦难,并解释这是如何工作的。

提前致谢…

我有一个类似的问题,我需要放大与文本。 我没有使用CATiledLayer,所以这可能会或可能不会为你工作。 我也没有使用ARC,所以如果你是,你也必须调整。

我想出的解决scheme是设置UIScrollViewDelegate方法,如下所示:

// Return the view that you want to zoom. My UIView is named contentView. -(UIView*) viewForZoomingInScrollView:(UIScrollView*)scrollView { return self.contentView; } // Recursively find all views that need scaled to prevent blurry text -(NSArray*)findAllViewsToScale:(UIView*)parentView { NSMutableArray* views = [[[NSMutableArray alloc] init] autorelease]; for(id view in parentView.subviews) { // You will want to check for UITextView here. I only needed labels. if([view isKindOfClass:[UILabel class]]) { [views addObject:view]; } else if ([view respondsToSelector:@selector(subviews)]) { [views addObjectsFromArray:[self findAllViewsToScale:view]]; } } return views; } // Scale views when finished zooming - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale { CGFloat contentScale = scale * [UIScreen mainScreen].scale; // Handle retina NSArray* labels = [self findAllViewsToScale:self.contentView]; for(UIView* view in labels) { view.contentScaleFactor = contentScale; } } 

我遇到了同样的问题,上面的代码不适合我的情况。 然后我跟着文档:

如果您打算在滚动视图中支持缩放,则最常见的技术是使用包含滚动视图的整个contentSize的单个子视图,然后向该视图添加其他子视图。 这允许您将单个“集合”内容视图指定为要缩放的视图,并且其所有子视图将根据其状态进行缩放。

https://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/UIScrollView_pg/CreatingBasicScrollViews/CreatingBasicScrollViews.html中的 “添加子视图”部分

我只是创build了一个空视图,并将我的CATiledLayer和所有其他子视图添加到该空视图。 然后将该空视图添加为滚动视图的唯一子视图。 而且,它像一个魅力。 沿着这些线路的东西:

 - (void)viewDidLoad { _containerView = [[UIView alloc] init]; [_containerView addSubView:_yourTiledView]; for (UIView* subview in _yourSubviews) { [_containerView addSubView:subview]; } [_scrollView addSubView:_containerView]; } -(UIView*) viewForZoomingInScrollView:(UIScrollView*)scrollView { return _containerView; }