试图找到在UIView中绘制UIImage的正确上下文

时间:2009-03-21 14:28:54

标签: cocoa-touch

我正在尝试在我的UIView中绘制背景图像。这是在UIAlertView委托方法alertView中: 我弹出上下文,因为在此之前我在一个名为game的OpenGL视图中使用了一个上下文。

UIGraphicsPopContext();
UIImage* background = [UIImage imageNamed:@"Background.png"];
[background drawAtPoint:CGPointMake(0.0, 0.0)];

// fade the game out
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[game setAlpha:0];
[UIView commitAnimations];

[game release];

我收到一堆错误消息,例如:CGContextSaveGState:无效的上下文 我尝试了没有弹出。 我想我需要做的是找到我的UIView的CGContextRef,并将其设置为我当前的上下文,但文档中不包含有关CGContextRef的信息。 如何显示图像?我试图在游戏视图淡出时显示游戏视图背后的图像。

感谢。

2 个答案:

答案 0 :(得分:4)

解决。我所要做的就是将UIImage放在UIImageView中,并将其添加到我视图的子视图中。

答案 1 :(得分:1)

@hyn是对的! 举个例子:

UIImageView *logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"38-airplane.png"]];