你能告訴我爲什麼這段代碼沒有顯示圖片嗎?爲什麼CALayer不顯示圖像?
CALayer *layerBack = [CALayer layer];
addedObject = [[UIImage alloc]initWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:[NSString stringWithFormat: @"%@%d", PREFIX, number] ofType:@"png"]];
layerBack.bounds=CGRectMake(0.0f,0.0f,selectedImage.size.height,selectedImage.size.width);
layerBack.position=CGPointMake(200,200);
layerBack.contents = (id)selectedImage.CGImage;
// in theory I think this line should be equal to selectedImage.CGImage, but when I do that, Xcode shows me an error!
[self.view.layer addSublayer:layerBack];
[layerBack display];
這石英的東西讓我瘋狂!請幫忙!
是的,圖像在那裏,正在工作,但我看到這個代碼後是一個空白的屏幕。
你爲什麼不只是使用的意見,特別是和的UIImageView它的imageNamed方法,從而降低這個代碼大約三線? – mahboudz 2009-09-10 18:33:00
,因爲我必須在最後將最終結果轉移到文件中,並且最後難以將轉換從UIView複製到CGLayers。 – SpaceDog 2009-09-10 22:34:55