ableViewCell中带有CATransform3D的UIV

ableViewCell中带有CATransform3D的UIV

本文介绍了UITableViewCell中带有CATransform3D的UIView =断断续续的滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义的 UITableViewCell ,在其中放置了一个子类 UIView (在 contentView 中, natch)。有问题的 UIView 显示一个方向箭头和两行支持文本。

I'm using a custom UITableViewCell, into which I am placing a subclassed UIView (within contentView, natch). The UIView in question displays a directional arrow and two lines of supporting text.

箭头是通过具有背景颜色的图层显示的和箭头形的面具。背景颜色会根据箭头指向的方向更改为两种可能性之一。

The arrow is displayed by means of a layer with a background color and an arrow-shaped mask. The background color changes to one of two possibilities depending on the direction the arrow is pointing.

该视图在需要更新时会收到 NSNotification 箭头(基于但不是与当前标题相同-每个单元格和视图都不同)。当它收到通知时,视图将调用私有方法来执行转换。这会为箭头图层设置动画,从而有效地将箭头图层绕其中心旋转到一个新方向,如下所示:

The view receives a NSNotification whenever it needs to update the arrow (based on, but not identical to, the current heading - each cell and view is different). When it receives notice, the view calls a private method to perform a transform. This animates the arrow layer, effectively rotating it around its center to a new direction, like so:

    // Update layer BG color, then ...

    [UIView setAnimationBeginsFromCurrentState:YES];
    CATransform3D transform = CATransform3DMakeRotation(DegreesToRadians(locationDirection), 0, 0, 1);
    _arrowLayer.transform = transform;

(nb: _arrowLayer 仅供内部使用

UIView 上还有一个属性来设置用于创建支持文本的信息。更改后,将调用 setNeedsDisplay drawRect:方法进行计算并绘制结果文本。

There is also a property on the UIView to set info used to create the supporting text. When this is changed, setNeedsDisplay is invoked, the drawRect: method makes the calculations and draws the resulting text.

那很好。但是, 我遇到了一个主要问题

That's all well and good. However, there is one major problem I'm encountering:

同时滚动表格视图箭头在某些大联盟的起伏滚动中产生动画效果,滚动时常常会停下来!即使这是 contentView 中的唯一视图(以最小测试用例的名义),也没关系。

Scrolling the table view at the same time the arrows are animating results in some major league choppy scrolling, often to the point of the scrolling stopping short! Even when this is the only view in contentView (in the name of minimal test cases), it doesn't matter.

如果不移动设备,滚动是可以接受的,但仍可以改进。

If the device is not moved, scrolling is moderately acceptable, but still open to improvement.

我希望我只是犯了一个基本错误(不要使用 drawRect:?以其他方式转换吗?以上都不是吗?)

I'm hopeful that I'm simply making a fundamental error (Don't use drawRect:? Do the transform some other way? None of the above?)

感谢

更新2011年10月4日::我尝试让 UITableViewController 观看 UIScrollViewDelegate (根据 UIScrollView 编程指南)以了解何时开始/停止滚动,然后每个方向箭头视图询问其委托(在这种情况下为Table VC)是否可以进行动画处理。但这也无济于事。如果动画正在进行中,我们很不幸。可能是 NSNotification ,方向箭头视图用于查找特定通知。 (但这听起来有些倒退,不是吗?给 other 对象一个可以发送的通知吗?嗯。)

UPDATE 4 Oct 2011: I tried having the UITableViewController watch UIScrollViewDelegate (per the UIScrollView programming guide) for when scrolling starts/stops, then each directional arrow view asks its delegate (the Table VC in this case) if it's OK to animate. This doesn't help much either though. If animation is in progress, we're out of luck. Perhaps NSNotification is in order, with the directional arrow view looking for a certain notification. (That sounds a bit backwards though, doesn't it? Giving other objects a notification that they can send out? Hmm.)

推荐答案

执行滚动的技巧是使用CoreGraphics而不是CoreAnimation。可以在此处找到说明:

The trick for performant scrolling is to use CoreGraphics instead of CoreAnimation. The explanation can be found here:

这是另一个StackOverflow问题:

Here is another StackOverflow Question:Tricks for improving iPhone UITableView scrolling performance?

因此在此示例中,我将尝试避开箭头蒙版并使用CG绘制

So in this example, I would try to avoid the arrow mask and draw it with CG

这篇关于UITableViewCell中带有CATransform3D的UIView =断断续续的滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 15:01