推荐什么核心图形技术来绘制非常自定义的UITableViewCells [英] What are recommended Core Graphics techniques for drawing very custom UITableViewCells

查看:51
本文介绍了推荐什么核心图形技术来绘制非常自定义的UITableViewCells的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我何时应该使用多层?
我可以使用剪切路径对角进行四舍五入,据我了解,这听起来比在CALayer上放置边界半径更有效。

When should I use multiple layers? I know I can use a clipping path to do the rounding on the corners, and from what I understand it sounds like that's more efficient than putting a border radius on a CALayer.

是否可以在drawRect中使用UIImageView的输出?
我知道您实际上不能使用该视图,但是我已经看到很多地方UIImageView的绘制图像效率更高而不是直接在drawRect中绘制它们。是否有可能以某种方式利用它们,还是只需要吸纳它并使用CG?

Is it possible to use the output from UIImageView in drawRect? I know you can't actually use the view, but I've seen in many places that UIImageView's are much more efficient for drawing images than drawing them straight in drawRect. Is it possible to leverage them there somehow, or do you just need to suck it up and use CG?

还有其他技巧,窍门和资源,可以帮助您最好地利用CG。欢迎绘制这样的单元格以获得尽可能高的FPS率。

Any other tips, tricks, and resources for the best way to draw a cell like this to get as high a FPS rate as possible are welcome.

推荐答案


何时应使用多层?

When should I use multiple layers?

不幸的是,答案是:必要时。层很便宜,并且肯定比UIView / UIImageView轻,但它们也不是传统iOS响应程序链的一部分(因为它们不能直接接收/中继触摸),但是单元本身通常会为您处理。苹果建议您避免使用 -drawRect:出于清洁的考虑,赞成使用拆分视图层次结构,但这并不意味着您必须为背景使用不同的视图。

Unfortunately, the answer is: whenever necessary. Layers are cheap, and certainly lighter than UIView/UIImageView, but they are also not a part of the traditional iOS responder chain (in that they cannot directly receive/relay touches), but the cell itself usually handles that for you. Apple recommends that you avoid -drawRect: in favor of a divided view hierarchy for cleanliness' sake, but that doesn't mean you have to have a different view for the background.


是否可以在drawRect中使用UIImageView的输出?

Is it possible to use the output from UIImageView in drawRect?

FPS的问题是一个好主意,在优化可能不是问题点的​​事物之前,先将其来源隔离开来。我将首先调查图像:您是否执行任何类型的缓存,或者每次调用 -drawRect:时,tableview单元都必须重绘它? UIImageView是否必须对图像执行任何类型的调整大小/缩放/解压缩?如果是这样,您是否考虑过一次调整图像大小,然后将结果保存到位图上下文中,而您只需从数组中提取并绘制它,而不用让UIImageView浪费时间为您做呢?

If you are having a problem with FPS, it's a good idea to isolate where it's coming from before optimizing away things that might not be problem spots. I would investigate the image first: are you performing any kind of caching, or does the tableview cell have to redraw it every single time it's -drawRect: is called? Does UIImageView have to perform any kind of resizing/scaling/decompression on the image? If so, have you considered resizing the image yourself once, then saving the result into a bitmap context which you simply pull from an array and draw, rather than have UIImageView waste it's time doing it for you?

只要您的其他问题未解决,我也将解决动画问题

对表格单元格的背景进行动画处理是微不足道的,尤其是如果您的单元格正在Core Graphics中绘制其背景,而不是使用CALayer(这意味着您将使用CABasicAnimation来为背景颜色设置动画,如此处)。我特别喜欢用于选定状态更改的TUI动画机制,因为它非常简单:

Animating the table cell's background is trivial, especially if your cell is drawing it's background in Core Graphics, rather than using a CALayer (which means you'll be using a CABasicAnimation to animate to and from a background color as detailed here). I especially like TwUI's animation mechanism for selected state changes, because it's just dead simple:


  1. 开始动画上下文。

  2. 有一个方法调用 -setNeedsDisplay ,或做一些您想动画化的工作。

  3. 制作动画。

  1. Start an animation context.
  2. Have a method that calls -setNeedsDisplay, or does some extra work you want animated.
  3. Commit the animations.

这篇关于推荐什么核心图形技术来绘制非常自定义的UITableViewCells的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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