![](/img/trans.png)
[英]CALayer.contents not rendering correctly in AVMutableComposition
[英]CALayer not rendering contents
這個難倒我了。 我有一個CALayer
,它是在UIViewController
的viewDidLoad
方法中創建的,如下所示:
- (void)viewDidLoad {
[super viewDidLoad];
UIImage* img = [UIImage imageNamed:@"foo.png"];
_imageLayer = [[CALayer alloc] init];
_imageLayer.bounds = CGRectMake( 0, 0, img.size.width, img.size.height);
_imageLayer.position = CGPointMake( self.view.bounds.size.width/2.0, self.view.bounds.size.height/2.0 );
_imageLayer.contents = (id)img.CGImage;
_imageLayer.contentsScale = img.scale;
[self.view.layer addSublayer:_imageLayer];
[_imageLayer setNeedsDisplay];
}
UIViewController
從 nib 加載並放入在代碼中創建的UITabBarController
中。
我的問題是,當UIViewController
變得可見時, CALayer
不會呈現其UIImage
內容。 我可以讓CALayer
渲染UIImage
的唯一方法是在UIViewController
可見后將其內容設置為UIImage
,例如在viewDidAppear:
方法中。
我真的更願意在viewDidLoad
方法中完成我的所有設置(這不是它的用途嗎?)。 我如何讓CALayer
渲染它的內容?
您不需要在圖層或超級視圖上設置setNeedsDisplay
。
setNeedsDisplay
告訴圖層或視圖它需要重繪其內容。 (對於視圖,它將調用drawRect:
來獲取新內容;對於 CALayer,它將詢問其委托。)請注意,這僅影響視圖或層本身,而不影響其子項。
由於您直接為層提供內容,因此您不希望 CA 丟棄該內容並要求替換。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.