CGLayer 是一个好的解决方案吗?

发布于 2024-08-12 11:05:35 字数 440 浏览 3 评论 0原文

我想为我的应用程序添加一些功能,并且我认为使用 CGLayer 是最好的方法,但之前从未做过任何 Quartz 绘图(除了一些基本教程之外)。

我的目的是在视图的上半部分显示我的应用程序将绘制的图像的完整视图(基于参数的基本几何形状),并在视图的下四分之一中显示该图像的放大部分用户触摸顶部图像的位置。我希望放大的部分以高分辨率显示,因此我认为应该将图像绘制到 640 x 640 CGLayer 上,然后在视图的上半部分 320 x 320 中绘制整个图层(因此缩放)向下以适合),以及用户在视图的左下角 160 x 160 中触摸的相关部分,但未缩放,因此您会看到主图像的四分之一。

当用户在主视图周围移动手指时,左下角的部分视图将从 CGLayer 中重新绘制,因此不会发生新的图像渲染,只是 CGLayer 绘制。

任何人都可以看到这种方法有任何我缺乏经验的大脑可能忽略的问题吗?

塔,朱尔斯。

I want to add a bit of functionality to my App, and I think that using a CGLayer is the best way of doing it, but have never done any Quartz drawing before (other than some basic tutorials).

My intention is to show a full view of an image that my App will draw (basic geometric shapes based on parameters) in the top half of a view, and show a zoomed in portion of that image in the bottom quarter of the view based on where the user has touched the top image. I want the zoomed in portion to show in a high resolution, so am thinking that I should draw the image onto, say, a 640 x 640 CGLayer, then draw that full layer in the top 320 x 320 half of the view (so scaled down to fit), and the relevant portion touched by the user in the bottom left 160 x 160 of the view, but unscaled, so you'd see a quarter of the main image.

When the user moves their finger around the main view, the portion view in the bottom left would be redrawn from the CGLayer, so no new image rendering is taking place, just CGLayer drawing.

Can anyone see any problem with this approach that my inexperienced brain may have missed?

Ta, Jools.

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

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

发布评论

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

评论(1

世态炎凉 2024-08-19 11:05:35

查看 CALayer 及其内容矩形参数。它将为您提供一种相当简单的方法来完成您想要的事情。您可以将图像视图图层的内容复制到缩放视图图层,如下所示:

[[zoomView layer] setContents:[[tapImageView layer] contents]];

然后您可以像这样设置contentsRect:

[[zoomView layer] setContentsRect:CGRectMake(x, y, 0.25, 0.25)];

您将计算x 和y 并在touchesMoved 中调用它。在此代码中设置为 0.25 的宽度和高度表示图像在缩放视图中显示的百分比。

如果您需要澄清,请告诉我。

Look at CALayer and it's contentsRect parameter. It will give you a fairly simple way to do exactly what you're wanting. You can copy the contents of your image view's layer to your zoomed view layer like this:

[[zoomView layer] setContents:[[tapImageView layer] contents]];

Then you set the contentsRect like this:

[[zoomView layer] setContentsRect:CGRectMake(x, y, 0.25, 0.25)];

You would calculate x and y and call this in touchesMoved. Width and height which are set to 0.25 in this code represent what percentage of the image will show in the zoomed view.

Let me know if you need clarification.

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