CALayer坐标系

发布于 2024-07-22 05:46:06 字数 660 浏览 5 评论 0原文

我对 Cocoa 很陌生,但想知道如何更改 CALayer 的坐标系。 我读了这篇文章 图层几何和变换来自核心动画编程指南,但仍然需要一些实用的建议。

默认坐标系的左下角为 (0,0)。 我想将其更改为图层的中心。 那可能吗?

我尝试过的:使用 CATransform3DTranslate 作为层框架的 MidX 和 MidY 的 sublayerTransform,子层显示在正确的位置。 在 setFrameSize 事件中,应该重新计算并再次应用转换。 我更喜欢自动刷新(没有“步骤”)。

或者我应该使用 kCAConstraintMidX 将子层 MidX 与层 MidX 相关联并使用偏移量? 事实上,我使用 CATextLayers 作为子图层,并且想要将文本居中对齐,从而将文本的中心相对于超级图层的中心定位。 我尝试了这个,但是当我调整超级图层的大小时它似乎不会自动刷新。

I'm quite new to Cocoa, but would like to know how to change a CALayer's coordinate system. I read the article Layer Geometry and Transforms from the Core Animation Programming Guide, but still need some practical advice.

The default coordinate system has (0,0) at the lower left corner. I would like to change this to the center of the layer. Is that possible?

What I tried: using a CATransform3DTranslate as sublayerTransform to MidX and MidY of the layer's frame, the sublayers are displayed at the right place. At the setFrameSize event the translation should then be recomputed and applied again. I would rather like an automatic refresh (without 'steps').

Or should I use kCAConstraintMidX to relate the sub layer MidX to the layer MidX and use an offset? In fact, I am using CATextLayers as sublayers, and want to align the text centered, thus position the center of the text relative to the center of the super layer. I tried this, but it doesn't seem to refresh automatically when I resize the super layer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧夏天 2024-07-29 05:46:06

查看名为 oalTouch 的 Apple 示例代码,它就是执行此操作的。

// Convert the view point to our layer / sound stage coordinate system, which is centered at (0,0)
CGPoint pointInLayer = CGPointMake(pointInView.x - [self frame].size.width / 2., pointInView.y - [self frame].size.height / 2.);

Check out Apple sample code called oalTouch which does this.

// Convert the view point to our layer / sound stage coordinate system, which is centered at (0,0)
CGPoint pointInLayer = CGPointMake(pointInView.x - [self frame].size.width / 2., pointInView.y - [self frame].size.height / 2.);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文