开发者

New CALayer.contents does not display until view is resized

I have a CALayer that needs to display frames of video. Every time a frame is rendered (as a CGImageRef), this method is called:

- (void)displayFrame:(CGImageRef)frame {
    [view layer].contents = (id)frame;
}

What's strang开发者_C百科e is that this, at first, will not display anything. Every time view is resized, a new frame is displayed, but sticks until view is resized again.

How do I fix this?


Is displayFrame: being called on the main thread? If not then I have found that it will not always draw. You can try forcing it to update by using [CATransaction flush] like:

- (void)displayFrame:(CGImageRef)frame {
    [view layer].contents = (id)frame;
    [CATransaction flush];
}

If that does not work then you might try including the layer construction code to help identify any peculiarities with this layer.


You probably need to do [[view layer] setNeedsDisplay]. The drawing system needs to be informed that updates have been made and the screen needs to be repainted. Resizing a view does this, but it seems that changing a layer's contents might not.


Using [CATransaction flush]; did the trick for me. I have to figure out what (if any) performance hit I take for displaying text using this approach.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜