具有最小绘制矩形的空 UIView:开销

发布于 2024-07-21 18:44:09 字数 717 浏览 5 评论 0原文

我有一个应用程序,它具有三个机械上很重要的嵌套视图,但没有视觉元素:

  • 一个普通的 UIView,它自己没有任何内容,只是用作 CALayers 的宿主。
  • 一个 UIScrollView (查询它的起源并用于在 3d 中定位 CALayers:我实际上只使用此视图来忠实地复制滚动视图的“机制”),
  • 滚动视图的内容:UIView 子类。 它只是获取触摸事件并将它们传递给委托 - 重要的是它的 UIResponder 机制。

托管 CALayers 的 UIView 是 UIImageView 的同级,UIImageView 是在其上绘制 CALayers 的背景图像。

我真的很想确保这些空的 UIView 没有任何与之相关的绘图或合成开销(时间或存储),或者如果不可能,则使此开销尽可能小,并理解它我也许可以决定是否应该尝试不同的方法。

在界面生成器中,我已将所有视图设置为在绘制之前不清除其上下文。 不过,我没有将它们设置为不透明,因为它们绝对不是不透明的 - 它们是完全透明的。 我发现我需要为滚动视图内容提供透明的清晰颜色(同样在 IB 中将背景颜色的不透明度设置为零),这表明它正在被绘制,这是我不想要的。

所以,简而言之,我不太清楚什么是被绘制的,什么不是被绘制的(有人知道像 Quartz Debug for iPhone/模拟器这样的工具吗?),或者如何阻止东西被绘制。

非常欢迎您的建议! 谢谢,本约翰

I have an application that has three nested views that are mechanically important, but have no visual elements:

  • A vanila UIView that doesn't have any content of its own, and is simply used as a host for CALayers.
  • A UIScrollView (that is queried for it's origin and used to position CALayers in 3d: I really only use this view to faithfully replicate the scroll view's "mechanics"),
  • The scroll view's contents: a UIView subclass. It simply picks up touch events and passes them to a delegate - all that is important are its UIResponder machinery.

The UIView hosting CALayers is a sibling of a UIImageView that is a background image over which the CALayers are drawn.

I'd really like to ensure that none of these empty UIViews have any drawing or compositing overhead (in time, or storage) associated with them, or if that's not possible, to get this overhead as small as possible, and to understand it so that I can perhaps decide if I should try a different approach.

In interface builder, I've set all of the views to not clear their context before drawing. I've not set them to be opaque though, because they definitely are not opaque - they are completely transparent. I've found that I need to give the scroll view contents a transparent clear colour (again in IB by setting the background colour's opacity to zero), and this suggests that it is being drawn, which I don't want.

So, in short, I've not got much idea of what is and isn't getting drawn (anyone know of a tool like Quartz Debug for iPhone / simulator?), or how to go about stopping things from getting drawn.

Advice would be very welcome! Thanks, Benjohn

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

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

发布评论

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

评论(2

删除→记忆 2024-07-28 18:44:09

实际上,您可以将 Instruments 与 Core Animation 工具结合使用来查看正在绘制的内容(请务必在退出之前禁用闪烁,因为它是设备上的全局设置)。

Actually, you can use Instruments with the Core Animation tool to see what's being drawn (be sure to disable flashing before you quit, because it's a global setting on your device).

任性一次 2024-07-28 18:44:09

除了我不能说的 UIScrollView 之外,您的其他视图不应该有太多的绘制开销,除非您手动调用 setNeedsDisplay 或将其图层的 needDisplayOnBoundsChange 属性设置为 YES。 视图绘制一次,然后将其图层缓存在 GPU 上。 重绘的成本很高,但只有当您通过我上面描述的方式手动触发它时才会发生这种情况。 这些视图和图层将使用内存,因此这是一个问题,特别是如果封闭视图变得非常大(尤其是接近 2048 x 2048 纹理限制大小)。 不幸的是,您对此无能为力。

作为建议,如果您所做的只是旋转和缩放 3D 图层,我可能建议您查看 一些示例代码,我为使用 Core Animation 在 iPhone 上进行 3-D 旋转和缩放而编写的。 它基于 Bill Dudney 编写的代码,其中触摸事件被处理为单个- 触摸移动和两指捏合手势,然后用于操纵 3D 图层。 这可以通过消除对 UIScrollView 和自定义内容视图的需要来简化您的代码。

Aside from the UIScrollView, which I can't speak for, your other views shouldn't have much in the way of drawing overhead unless you are manually calling setNeedsDisplay or have set their layer's needsDisplayOnBoundsChange property to YES. The views draw once and cache their layers on the GPU at that time. Redrawing is expensive, but that only occurs if you manually trigger it via the means I described above. These views and layers will use memory, so that is a concern, particularly if the enclosing views get very large (especially near the 2048 x 2048 texture limit size). Unfortunately, there's not much you can do about that.

As a suggestion, if all you are doing is rotating and scaling the layers in 3-D, I might suggest that you take a look at some sample code that I had written for doing 3-D rotation and scaling on the iPhone using Core Animation. It's based on code written by Bill Dudney, where touch events are processed into single-touch moves and two-finger pinch gestures and then used to manipulate layers in 3-D. This might simplify your code by removing the need for a UIScrollView and your custom content view.

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