Ios 工具栏按钮选择器未在控制台中随消息一起激发:<;错误>;:CGContextSaveGState:上下文无效
我用下面的代码以编程方式添加Ios 工具栏按钮选择器未在控制台中随消息一起激发:<;错误>;:CGContextSaveGState:上下文无效,ios,objective-c,core-graphics,uitoolbar,cgcontext,Ios,Objective C,Core Graphics,Uitoolbar,Cgcontext,我用下面的代码以编程方式添加UIToolbar。它应该处理基本的图像编辑,但是当我点击工具栏上的任何按钮时,我会收到这个错误消息,并且不会调用选择器。viewController嵌入到UINavigationController中,并具有UIScrollView和UIImageView 我在这里发现,在某些情况下,这个错误可能会被忽略,因为它是iOS中的一个bug,但是在我的情况下,我的选择器也不会随此消息一起调用。我还发现有人在使用零大小的CGContext时出现此错误,我使用CGContex
UIToolbar
。它应该处理基本的图像编辑,但是当我点击工具栏上的任何按钮时,我会收到这个错误消息,并且不会调用选择器。viewController嵌入到UINavigationController
中,并具有UIScrollView
和UIImageView
我在这里发现,在某些情况下,这个错误可能会被忽略,因为它是iOS中的一个bug,但是在我的情况下,我的选择器也不会随此消息一起调用。我还发现有人在使用零大小的CGContext时出现此错误,我使用CGContext进行了一些图像捕获,但它工作正常,与工具栏按钮和选择器无关。有什么建议吗
<Error>: 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.
我最后发现了这个问题。我有一个点击手势识别器,它取消了触摸事件,但它们从未到达选项卡栏。仍然不知道CGContext错误出现的原因
- (void)addBasicToolbar
{
// create toolbar
UIToolbar *basicToolbar = [[UIToolbar alloc] init];
basicToolbar.barStyle = UIBarStyleBlack;
basicToolbar.translucent = NO;
basicToolbar.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:basicToolbar];
// add constraints
NSDictionary *metrics = @{@"barHeight":@44.0};
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[basicToolbar]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(basicToolbar)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[basicToolbar(==barHeight)]|" options:0 metrics:metrics views:NSDictionaryOfVariableBindings(basicToolbar)]];
// add bar buttons
UIBarButtonItem *rotateLeft = [[UIBarButtonItem alloc] initWithTitle:@"Rotate left" style:UIBarButtonItemStylePlain target:self action:@selector(rotateLeft)];
UIBarButtonItem *rotateRight = [[UIBarButtonItem alloc] initWithTitle:@"Rotate right" style:UIBarButtonItemStylePlain target:self action:@selector(rotateRight)];
UIBarButtonItem *resetButton = [[UIBarButtonItem alloc] initWithTitle:@"Revert to original" style:UIBarButtonItemStylePlain target:self action:@selector(resetToOriginal)];
UIBarButtonItem *markupButton = [[UIBarButtonItem alloc] initWithTitle:@"Add markup" style:UIBarButtonItemStylePlain target:self action:@selector(addMarkup)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
basicToolbar.items = @[resetButton, flexibleSpace, rotateLeft, rotateRight, flexibleSpace, markupButton];
}
- (void)rotateLeft
{
NSLog(@"rotate left called"); // but is actually not called
}