English 中文(简体)
[CALAYER 绘图文
原标题:Ghosting in [CALayer drawInContext]

我以可滚动的图表绘制,使用自定义的CaLayer 扩展,在[ MyCustomCaLayer draw Incontext] 中,有一堆 CGContextAddurveTopoint 呼叫。

我其实没有绘制整张图的长度,相反,我每次更新 UIPanGestureRecognizer 以反映新的水平偏移时,都会重新绘制图层的内容。 这样, 我只能绘制图的可见部分, 而图层的界限只延伸到屏幕的大小 。

[ MyCustomCaLayer setNeeds Display] 被调用时,当图形数据改变或锅面偏移变化,从而导致引用 [ MyCustomCaLayer draw Incontext]

然而,每当我在横跨期间重新铺设我的层层时,我都会得到这种奇怪的鬼魂。 略微的搜索表明, 它可能是一个 < a href="https:// developmenter. apple. com/library/mac/document/Cocoa/Coceptitual/Codefitual/CoreAnimation_guide/articles/AnimateLayers. html# //apple_ref/doc/uid/TP400006085- SW7" rel="nofollow norefererr" > implical 动画 被重新绘制层的内容所引用, 但我找不到一个明确的答案。

Here s what the graph looks like at rest: At rest

And here it is during panning, with the ghosting redraw: During panning

当然,当我 do 绘制整张图并调整图层 < code> position 属性,使其不会消失,但记忆中有一个很长的位图似乎像一个坏东西。

有人见过这种鬼魂吗?如果它(如我所怀疑的)是隐含的动画,我怎么能禁用动画呢?

最佳回答

它可能是一个隐含的动画。 重新绘制( 内容的变化) 和核心动画中的其他所有内容一样被动画 。

有许多方法可以防止这种情况发生, 如果你将CaLayer 重新分类, 来绘制最佳的图, 就是推翻 - [CaLayer Action for ForKey:], 返回零, 更改内容 :

- (id<CAAction>)actionForKey:(NSString *)key 
{
    if ([key isEqualToString: @"contents"]) 
    {
        return nil;
    }

    return [super actionForKey: key];
}
问题回答

另一种使隐含动画失效的方法是:

    [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];

如果禁用隐含动画不起作用, 那么您可以考虑使用滚动视图, 将整件事绘制成一个大视图, 也就是滚动视图的内容 。

编辑:

我忘了提过这个方法 需要你在CATransaction块内修改





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签