“contentScaleFactor"背后的秘密是什么?UIView 与 CATiledLayer 一起使用时? [英] What is the secret behind "contentScaleFactor" of UIView when used with CATiledLayer?

查看:24
本文介绍了“contentScaleFactor"背后的秘密是什么?UIView 与 CATiledLayer 一起使用时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在开发一个受 iOS SDK 附带的ZoomingPDFViewer"示例启发的应用程序.在某些时候,我发现了以下代码:

I'm working on an application inspired by the "ZoomingPDFViewer" example that comes with the iOS SDK. At some point I found the following bit of code:

// to handle the interaction between CATiledLayer and high resolution
// screens, we need to manually set the tiling view's 
// contentScaleFactor to 1.0. (If we omitted this, it would be 2.0 
// on high resolution screens, which would cause the CATiledLayer 
// to ask us for tiles of the wrong scales.)
pageContentView.contentScaleFactor = 1.0;

我试图了解有关 contentScaleFactor 及其作用的更多信息.在阅读了所有提到它的 Apple 文档后,我搜索了谷歌,但从未找到它实际作用的明确答案.

I tried to learn more about contentScaleFactor and what it does. After reading everything of Apple's documentation that mentioned it, I searched Google and never found a definite answer to what it actually does.

这里有一些我很好奇的事情:

Here are a few things I'm curious about:

  1. 当绘制 UIView 的/CALayer 的内容时,contentScaleFactor 似乎对图形上下文有某种影响.这似乎与高分辨率显示器(如 Retina 显示器)有关.contentScaleFactor 究竟有什么样的影响,对什么有什么影响?

  1. It seems that contentScaleFactor has some kind of effect on the graphics context when a UIView's/CALayer's contents are being drawn. This seems to be relevant to high resolution displays (like the Retina Display). What kind of effect does contentScaleFactor really have and on what?

当使用 UIScrollView 并将其设置为缩放时,比如说,我的 contentViewcontentView 的所有子视图也被缩放.这是如何运作的?UIScrollView 修改了哪些属性使视频播放器变得模糊和放大?

When using a UIScrollView and setting it up to zoom, let's say, my contentView; all subviews of contentView are being scaled, too. How does this work? Which properties does UIScrollView modify to make even video players become blurry and scale up?

TL;DR:UIScrollView 的缩放功能如何在幕后"工作?我想了解它是如何工作的,以便我可以编写正确的代码.

TL;DR: How does UIScrollView's zooming feature work "under the hood"? I want to understand how it works so I can write proper code.

非常感谢任何提示和解释!:)

Any hints and explanation is highly appreciated! :)

推荐答案

坐标以点而不是像素表示.contentScaleFactor 定义了点和像素的关系:如果是1,点和像素是一样的,如果是2(如retina display),则意味着每个点都有两个像素.

Coordinates are expressed in points not pixels. contentScaleFactor defines the relation between point and pixels: if it is 1, points and pixels are the same, but if it is 2 (like retina displays ) it means that every point has two pixels.

在普通绘图中,使用点意味着您不必担心分辨率:在 iphone 3(比例因子 1)和 iphone4(比例因子 2 和 2x 分辨率)中,您可以使用相同的坐标和绘图代码.但是,如果您正在绘制图像(直接作为纹理...)并且仅使用法线坐标(点),您不能相信像素到点的映射是 1 比 1.如果这样做,那么每个像素如果 scaleFactor 为 2(x 方向为 2,y 方向为 2),则图像将对应于 1 个点,但对应于 4 个像素,因此图像可能会变得有点模糊

In normal drawing, working with points means that you don't have to worry about resolutions: in iphone 3 (scaleFactor 1) and iphone4 (scaleFactor 2 and 2x resolution), you can use the same coordinates and drawing code. However, if your are drawing a image (directly, as a texture...) and just using normal coordinates (points), you can't trust that pixel to point map is 1 to 1. If you do, then every pixel of the image will correspond to 1 point but 4 pixels if scaleFactor is 2 (2 in x direction, 2 in y) so images could became a bit blurred

使用 CATiledLayer 时,您可以使用比例因子 2 获得一些意想不到的结果.我猜有 UIView 一个 contentScaleFactor==2 和layer a contentScale==2 混淆系统,有时会乘以比例.也许 Scrollview 也会发生类似的事情.

Working with CATiledLayer you can have some unexpected results with scalefactor 2. I guess that having the UIView a contentScaleFactor==2 and the layer a contentScale==2 confuse the system and sometimes multiplies the scale. Maybe something similar happens with Scrollview.

希望这能澄清一点

这篇关于“contentScaleFactor"背后的秘密是什么?UIView 与 CATiledLayer 一起使用时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆