我有一个UIScrollView,里面包含一个子UIView(CATiledLayer),然后还有更多的子视图(其中一些是UITextView)。
缩放后,所有东西都变得模糊不清。
我已经阅读了各种相关文章,它们似乎都表明我必须处理scrollViewDidEndZooming,然后“做一些变换处理、调整框架和微调内容偏移”。请问有人能解释一下这是如何工作的吗?
提前致谢...
缩放后,所有东西都变得模糊不清。
我已经阅读了各种相关文章,它们似乎都表明我必须处理scrollViewDidEndZooming,然后“做一些变换处理、调整框架和微调内容偏移”。请问有人能解释一下这是如何工作的吗?
提前致谢...
我曾遇到类似的问题,需要在文本上进行缩放。我的情况并没有使用CATiledLayer,所以这个解决方案可能适用或不适用于你。我也没有使用ARC,所以如果你正在使用,你还需要进行相应的调整。
我提出的解决方案是将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;
}
}
- (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;
}