CATiledLayer 得到一个不正确的框架& contextCTM.a 值 (zoomScale)
在 WWDC2010 Session 104 之后,我刚刚在 UIScrollView
中为 10000 x 8078 px 图像创建了一个 CATiledLayer。
我对框架和框架感到困扰zoomScale
当视图首次显示在其顶层
- (如会话 104 中)时,我
- 在我的绘制矩形中将
levelsOfDetail
定义为 4,我调用CGFloat lScale = CGContextGetCTM(lContext)。 a;
奇怪的是,在运行时lScale被分配为0.124907158,而不是预期的0.125。
此外,传递给 drawRect
的 rect
也具有浮点值,例如
- rect.origin.x = 4099.04443
- rect.origin.y = 6144
- rect.size.width = 2049.52222
- rect。 size.height = 2048
最让我恼火的是,CATiledLayer
的框架显示原点 0 x 26.93,即使我使用 initWithFrame
使用 0x0 原点创建了tiledImageView。
我有什么想法可以找到对此负责的计算吗?
编辑: 我找到了奇怪的框架位置的来源,即 ScrollView 边界被错误地设置为 450 像素。那应该是 420 像素。 UIScrollView 中的layoutSubview 例程有一个中心视图例程,它无意中调整了y 坐标。
following WWDC2010 Session 104 I just created a CATiledLayer within a UIScrollView
for a 10000 x 8078 px image.
I am troubled with the frame & zoomScale
when the view is first shows at its top level
- like in session 104 I defined
levelsOfDetail
as 4 - in my drawRect I call
CGFloat lScale = CGContextGetCTM(lContext).a;
Strangely at runtime lScale is assigned 0.124907158, not 0.125 as expected.
As well the rect
passed to drawRect
has floatpoint values, such as
- rect.origin.x = 4099.04443
- rect.origin.y = 6144
- rect.size.width = 2049.52222
- rect.size.height = 2048
Most irritating for me is that the frame of the CATiledLayer
shows an origin 0 x 26.93 even though I created the tiledImageView using initWithFrame
using a 0x0 origin.
Any ideas where I can find the calculation that is responsible for this?
EDIT:
I found the source for the wierd frame position, which is the ScrollView bounds being incorrectly set at 450 px. that should be 420 px. The layoutSubview routine in the UIScrollView has a center view routine that inadvertently adjusted the y coordinate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决这个问题的方法。
WWDC 2010 会话 104 示例有两个控制视图行为的
UIScrollView
方法。第一个是
configureForImageSize
,我在之前发布的答案中提到过,其中设置了缩放比例。由于所解释的浮点差异,生成的 imageView 边界带有之前突出显示的小数(请参阅 wx/hx 或 wy/hy)。
为了清理这个问题,我使用了
layoutSubviews
的覆盖来计算视图框架:请注意,我在对其进行任何其他操作之前对框架大小进行了舍入!
I found a cure to this.
The WWDC 2010 session 104 sample has two
UIScrollView
methods that control the view behaviour.The first is
configureForImageSize
that I mentioned in my previously posted answer where the zoomscales are set.Due to the explained float-point difference the imageView-bounds get generated with the decimals as highlighted before (see wx/hx or wy/hy).
To get clean this up I used the override of
layoutSubviews
where I calculate the view frame:Note that I round the frame size before doing anything else with it!
我对错误分析有了进一步的了解。
在
UIScrollView
中 mImageSize 为 10000x8078 和 320x450 边界,我使用会话 104 示例中的configureForImageSize
计算,如下所示:调试器显示以下值:
因此我收集图像与边界相关的大小会导致浮点计算差异。当生成
CATiledLayer
时,边界始终是浮点值。如果这是原因,我怎样才能得到一个数学方法,而不必调整图像大小(丑陋的想法)???
I got a little further in my bug analysis.
Having an mImageSize of 10000x8078 and 320x450 Bounds in the
UIScrollView
I used theconfigureForImageSize
calculations from the session 104 example as follows:The debugger shows the following values:
so I gather the image size in relation to the bounds leads to a floatpoint calculation difference. When the
CATiledLayer
is generated the bounds are alway floatpoint values.If that is the cause, how can I get a mathematical way out of this without having to resize the image (ugly thought)???