gpt4 book ai didi

ios - UIScrollView 缩放后重绘 subview

转载 作者:可可西里 更新时间:2023-11-01 06:18:35 25 4
gpt4 key购买 nike

我有一个带有子 UIView (CATiledLayer) 的 UIScrollView - 然后我有该 View 的更多 subview (其中一些是 UITextView)

缩放后一切都模糊了。

我已经阅读了有关该主题的各种文章,它们似乎都表明我必须处理 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;
}
}

关于ios - UIScrollView 缩放后重绘 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8536632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com