绘图类允许图层控制 [英] Drawing class to allow layer control

查看:150
本文介绍了绘图类允许图层控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Quartz 的帮助下实现一个绘图类。
我想能够保存在不同图层上绘制的部分。我想要这些图层是可检索的,所以我可以根据命令删除/隐藏/显示图层。



我可以保存多个 CGLayerRef 作为我的类的 NSMutableArray 属性,然后能够检索它们?如果是,你能指点一个例子。



如果在上面的架构有任何缺陷,请指向我的替代解决方案,可以帮助我实现分层


解决方案

创建,当然可以存储在NSMutableArray中,您可以稍后通过对其属性进行动画处理或要求他们重新绘制自己来处理它们。



通常,自定义UIView,在该视图中创建和管理图层。这些图层是该视图的成员变量,或者将它们存储在数组中。由于事情发生在您的应用程序中,您的视图会相应地动画化图层。通常,您要对触摸事件(您也在该特定视图中实现 - 触摸基础/已移动...)做出反应,并对图层进行动画处理。



CALayer绘制自己和缓存只要你调用 [layer setNeedsDisplay] 或它的边界(大小)的内容都会改变(好吧,如果 needsDisplayOnBoundsChange 为真)。实际上在我的所有应用程序中,这样的重绘发生非常罕见 - 只有当数据更改,层需要重绘。动画层,转换它们的大小,旋转,改变位置 - 层在任何这些都不重画。隐藏,显示,改变透明度 - 不需要重绘。



你正在说的绘图类 - 你实际上只有两个选项 - $ c> CALayer 并覆盖 drawInContext:,或者创建基本 CALayer 委托,你在 drawLayer:inContext:中绘制。我个人更喜欢创建代表。


I would like to implement a drawing class with the help of Quartz. I want to be able to save parts of what is drawn on separate layers. I want these layers to be retrievable, so I can delete/hide/show layers on command.

Can I save multiple CGLayerRef as a NSMutableArray property of my class and then be able to retrieve them? If yes, can you point me to an example.

If there are any flaws in the "architecture" above, please point me to alternative solutions that could help me accomplish layered control over graphs.

Thank you.

解决方案

CALayers that you create, can of course be stored in NSMutableArray, and you can work with them later on, usually by animating their properties, or asking them to redraw themselves.

Usually you create a custom UIView, create and manage layers within that view. Those layers are either member variables of that view, or you store them in an array. As things are happening in your app, your view animates the layers accordingly. Usually you want to react on touch events (which you also implement in that particular view - touchesBegan/Moved...) and animate the layers.

CALayer draws itself and caches the content for as long as you call [layer setNeedsDisplay], or it's bounds (size) are changed (well, if needsDisplayOnBoundsChange is true). Practically in all my apps I did, such redrawing happens very rarely - only if data are changed, and layer needs to redraw. Animating layers, transforming their size, rotation, changing position - layer is not redrawn during any of these. Hiding, showing, changing transparency - no redraw is required.

That "drawing class" you are talking about - you actually have only two options - either you extend CALayer and overwrite drawInContext:, or you create basic CALayer, set its delegate, and there you draw in drawLayer:inContext:. I personally prefer creating delegates.

这篇关于绘图类允许图层控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆