Jes*_*ock 3 iphone scaling objective-c uitextview uiview
我正在尝试创建一个更高分辨率的UIView图像,特别是UITextView.
这个问题和答案正是我想要弄清楚的:
但是,当我这样做时,我的文字仍然模糊:
self.view.transform = CGAffineTransformMakeScale(2.f, 2.f);
[myText setContentScaleFactor:2.f]; // myText is a subview of self.view object
Run Code Online (Sandbox Code Playgroud)
我也在UILabel的Apple示例项目"UICatalog"中尝试过相同的操作,它也很模糊.
我无法理解为什么它会从另一个问题中为Warrior工作而不适合我.我会问那里 - 但我似乎无法在那里留下评论或问题.
任何建议将不胜感激,谢谢.
正如@dbotha指出的那样设置contentScaleFactor和contentsScale实际上是关键,但是你必须分别遍历视图和层次层次结构,以便到达CATiledLayer实际进行文本渲染的每个内部.添加屏幕比例也可能有意义.
所以正确的实现将是这样的:
- (void)updateForZoomScale:(CGFloat)zoomScale {
CGFloat screenAndZoomScale = zoomScale * [UIScreen mainScreen].scale;
// Walk the layer and view hierarchies separately. We need to reach all tiled layers.
[self applyScale:(zoomScale * [UIScreen mainScreen].scale) toView:self.textView];
[self applyScale:(zoomScale * [UIScreen mainScreen].scale) toLayer:self.textView.layer];
}
- (void)applyScale:(CGFloat)scale toView:(UIView *)view {
view.contentScaleFactor = scale;
for (UIView *subview in view.subviews) {
[self applyScale:scale toView:subview];
}
}
- (void)applyScale:(CGFloat)scale toLayer:(CALayer *)layer {
layer.contentsScale = scale;
for (CALayer *sublayer in layer.sublayers) {
[self applyScale:scale toLayer:sublayer];
}
}
Run Code Online (Sandbox Code Playgroud)