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

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

问题描述

问候,

我正在开发一款受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文档的所有内容之后,我搜索了Google并且从未找到确切的答案。

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. 似乎 contentScaleFactor 对此有一些影响绘制UIView的/ CALayer内容时的图形上下文。这似乎与高分辨率显示器(如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?

使用<$ c $时c> UIScrollView 并将其设置为缩放,比方说,我的 contentView ; contentView 的所有子视图也正在缩放。这个怎么用?哪些属性 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(如视网膜显示),则表示每个点都有两个像素。

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(scaleFactor 1)和iphone4(scaleFactor 2和2倍分辨率),您可以使用相同的坐标和绘图代码。但是,如果您正在绘制图像(直接,作为纹理......)并且仅使用法线坐标(点),则您不能相信像素到点的地图是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 你可以使用scalefactor 2获得一些意想不到的结果。我想有 UIView a contentScaleFactor = = 2 并且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”背后的秘密是什么?与CATiledLayer一起使用的UIView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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