2012-04-06 5 views
0

View Programming Guide for iOS on pg。 57は、コードのこの部分を持っている:myLayer = layerContents.CGImage;このCALayerセットアップコードで何が問題になっていますか?

// Create the layer. 
CALayer* myLayer = [[CALayer alloc] init]; 
// Set the contents of the layer to a fixed image. And set 
// the size of the layer to match the image size. 
UIImage layerContents = [[UIImage imageNamed:@"myImage"] retain]; 
CGSize imageSize = layerContents.size; 
myLayer.bounds = CGRectMake(0, 0, imageSize.width, imageSize.height); 
myLayer = layerContents.CGImage; 

あなたが最後の行でこれをしたいと思う理由。一つは、オブジェクトが一致しないので型の問題です。しかし、それは最初のステートメントで作成されたオブジェクトを置き換えています!

私には何が欠けていますか?

答えて

2

このドキュメントは間違っています。おそらく次のようになります:

myLayer.contents = (id)layerContents.CGImage; 

これは、レイヤの内容を設定する1つの方法です。 docs for contents

を参照してください
関連する問題