contentsRect属性的坐标系吗

contentsRect属性的坐标系吗

本文介绍了有人可以向我解释CALayer contentsRect属性的坐标系吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我意识到 CALayer 的 contentsRect 属性(这里的文档)允许用户定义用于绘图的图层数量,但是我认为我不明白坐标系是如何工作的。I realize that the contentsRect property of CALayer (documentation here) allows one to define how much of the layer to use for drawing, but I do not understand how the coordinate system works, I think.当宽度/高度较小时,用于内容的区域似乎更大,反之亦然。同样,负x,y位置似乎将内容区域向下移动到右边,这与我的直觉相反。It seems that when the width/height are smaller, the area used for content is bigger and vice versa. Similarly, negative x,y positions seem to move the content area down and to the right which is the opposite of my intuition.有人可以解释为什么会这样吗?我确信有一个很好的理由,但我认为我缺少一些图形编程背景。Can someone explain why this is? I'm sure there is a good reason, but I assume I'm missing some graphics programming background.推荐答案否,你正在考虑错误。 contentsRect 指定 的哪一部分 内容图像将显示在图层中。The contentsRect specifies which part of the contents image will be displayed in the layer.然后该部分根据布置在图层中code> contentsGravity 属性。That part is then arranged in the layer according to the contentsGravity property.如果这是 kCAGravityResize ,默认情况下,这将导致部分成为调整大小以适合图层。这可以解释你所看到的违反直觉的行为 - 你让 contentsRect 更小,但是这个图层看起来大小相同,而且它似乎放大了选定的图像部分。如果将 contentsGravity 设置为 kCAGravityCenter ,则可能会更容易理解,这不会调整大小。If this is kCAGravityResize, the default, this will cause the part to be resized to fit the layer. That would explain the counterintuitive behavior you're seeing -- you make contentsRect smaller, but the layer appears to be the same size, and it appears to "zoom in" on the selected part of the image. You might find it easier to understand if you set contentsGravity to kCAGravityCenter, which won't resize.大多数情况下,你会将 contentsRect 设置为身份rect的某个子矩形 { {0,0},{1,1}} ,因此您选择仅查看部分内容。Most of the time, you would set the contentsRect to some sub-rect of the identity rect { {0, 0}, {1, 1} }, so you choose to see only part of the contents.(如果您愿意,可将其视为百分比 - 如果 contentsRect 的大小为 {0.5,0.5} ,您选择内容的50%。)(Think of these as percentages if you like -- if contentsRect has a size of {0.5, 0.5}, you're choosing 50% of the contents.)如果 contentsRect 的一部分超出了标识符,那么CA将扩展内容的边缘像素向外。这在某些情况下很方便,但它不是你自己使用的东西 - 你可以将它与面具或其他一些层结合使用以达到某种效果。If part of the contentsRect goes outside the identity rect, then CA will extend the edge pixels of the contents outwards. This is handy in some cases, but it's not something you'd use on its own -- you'd use it in combination with a mask or with some other layers to achieve some effect. 这篇关于有人可以向我解释CALayer contentsRect属性的坐标系吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-29 22:01