0

我有一个UIImageViewUIViewController想在现有的 imageView 上添加一个简单的图像。

viewDidLoad 方法如下所示:

    UIImage *test;
    test = [UIImage imageNamed:@"position-dot.png"];

    [test drawAtPoint:CGPointMake(100,100) ];

我收到的部分错误消息如下所示:

CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

CGContextSetBlendMode: invalid context 0x0. This is a serious error.

我测试了重置我的iOS模拟器(其他线程中的解决方案),但这并没有解决问题。

4

1 回答 1

1

虽然我上述评论中的方法确实使警告静音,但我发现图像未按预期显示。我发现让 drawAtPoint 工作的最简单方法是将 UIView 子类化并将您拥有的确切代码放入 drawRect 的实现中:就像这样。

- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    UIImage *test;
    test = [UIImage imageNamed:@"position-dot"];
    [test drawAtPoint:CGPointMake(100.0, 100.0)];
}

然后,在您的控制器中:

MyViewSubclass *view = [[MyViewSubclass alloc] initWithFrame:self.view.frame];
[self.view addSubview:view];
于 2014-04-02T17:28:16.750 回答