我在 UIViewController
中有一个 UIImageView
,我想在现有的 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:无效上下文 0x0。这是一个严重的错误
。
我测试过重置我的 iOS 模拟器(其他线程中关于此的解决方案),但这并没有解决问题。
最佳答案
虽然我上述评论中的方法确实消除了警告,但我发现图像没有按我的预期显示。我发现使 drawAtPoint 工作的最简单方法是子类化 UIView 并将您拥有的确切代码放入 drawRect: 的实现中,就像这样。
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
UIImage *test;
test = [UIImage imageNamed:@"position-dot"];
[test drawAtPoint:CGPointMake(100.0, 100.0)];
}
然后,在您的 Controller 中:
MyViewSubclass *view = [[MyViewSubclass alloc] initWithFrame:self.view.frame];
[self.view addSubview:view];
关于ios - 无法绘制图像。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22817574/