quartz2d 翻译起源

发布于 2024-10-12 13:11:50 字数 564 浏览 2 评论 0原文

我对quartz2d的理解是代码CGContextTranslateCTM(context, x, y);平移坐标系。我有一个quartz2d 视图,上面有很多形状,用户需要能够平移和缩放它。但是,当使用 CGContextScaleCTM(context,scaleX,scaleY); 代码时,所有内容都会围绕原点缩放,而不是用户正在查看的视点中心。

我的解决方案是使用以下代码:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 512.0+offset.x, 384.0+offset.y);  
//(512, 384) is the center of the iPad screen
CGContextScaleCTM(context, scale, scale);

您可以很好地平移,但事情仍然会扩展到角落。怎么了?

编辑:哦。哇。呃。如果移动原点,形状也会移动,因此您无法相对于形状移动它。现在我知道出了什么问题,但我该怎么做?(独立于形状移动原点)

My understanding of quartz2d is that the code CGContextTranslateCTM(context, x, y); translates the coordinate system. I have a quartz2d view with lots of shapes on it, and the user needs to be able to pan around and zoom it. However, when using the CGContextScaleCTM(context, scaleX, scaleY); code, everything scales around the origin, not the center of the viewpoint the user is viewing.

My solution to this was to use the following code:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 512.0+offset.x, 384.0+offset.y);  
//(512, 384) is the center of the iPad screen
CGContextScaleCTM(context, scale, scale);

You can translate around fine, but things still scale into the corner. What's wrong?

EDIT: Oh. Wow. Duh. If you move the origin, the shapes move too, so you can't move it relative to the shapes. Now I know what's wrong, but how do I do that?(move the origin independently of the shapes)

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

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

发布评论

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

评论(2

还给你自由 2024-10-19 13:11:50

没有太多使用 CoreGraphics C API 的经验,但您是否考虑过将视图粘贴到 UISCrollView 上?如果该功能存在并且免费,为什么不使用它呢?

Don't have much experience with using the CoreGraphics C API, but have you considered sticking your view onto a UISCrollView? If the functionality is there and its free, why not use it?

白鸥掠海 2024-10-19 13:11:50

您可以为每个形状创建一个 UIView 类。
为每个要移动的形状实例化一个 UIView 对象。

然后使用 shape.center = CGPointMake(x,y); 更改视图对象的中心。
大概的方法是调用bounds.center,在UIView中查看。

这将自动调用drawRect(),一切都很好!

You could create a UIView class for each shape.
The instantiate an UIView object for each shape to move arround.

Then you change the center of tht view objects with shape.center = CGPointMake(x,y);
Probably the method is calls bounds.center, look in UIView.

This will automatically call drawRect() and all is fine!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文