我正在使用zxing库来扫描条形码。每当我扫描错误的条形码时,邮件编写者都会打开一封邮件,说明扫描了错误的条形码。当我们解雇邮件编辑器时,我们可以再次扫描。但是,当我解雇邮件编辑器时,我的应用程序崩溃说“[CALayer isKindOfClass:]:发送到解除分配的实例的消息”
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));// app crashed at this line
}
}
这就是我所拥有的
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
[self.capture.layer removeFromSuperlayer];
[self.view.layer removeFromSuperlayer];
self.view = nil;
self.capture=nil;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.capture.delegate = self;
self.capture.layer.frame = self.view.bounds;
_scanRectView.layer.borderColor=[UIColor redColor].CGColor;
_scanRectView.layer.borderWidth = 2;
CGAffineTransform captureSizeTransform = CGAffineTransformMakeScale(320 / self.view.frame.size.width, 480 / self.view.frame.size.height);
self.capture.scanRect = CGRectApplyAffineTransform(self.scanRectView.frame, captureSizeTransform);
}
- (void)viewDidLoad
{
[super viewDidLoad];
//initialising the zxing library to start the camera
self.capture = [[ZXCapture alloc] init];
self.capture.camera = self.capture.back;
self.capture.focusMode = AVCaptureFocusModeContinuousAutoFocus;
self.capture.rotation = 90.0f;
self.capture.layer.frame = self.view.bounds;
[self.view.layer addSublayer:self.capture.layer];
[self.view bringSubviewToFront:self.scanRectView];
[self.view bringSubviewToFront:self.decodedLabel];
}
请告诉我,我在哪里做错了。
提前致谢。
答案 0 :(得分:2)
我认为你的viewDidDisappear方法错误
它将是
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
[self.capture.layer removeFromSuperlayer];
self.capture=nil;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//initialising the zxing library to start the camera
self.capture = [[ZXCapture alloc] init];
self.capture.camera = self.capture.back;
self.capture.focusMode = AVCaptureFocusModeContinuousAutoFocus;
self.capture.rotation = 90.0f;
self.capture.layer.frame = self.view.bounds;
[self.view.layer addSublayer:self.capture.layer];
[self.view bringSubviewToFront:self.scanRectView];
[self.view bringSubviewToFront:self.decodedLabel];
self.capture.delegate = self;
self.capture.layer.frame = self.view.bounds;
_scanRectView.layer.borderColor=[UIColor redColor].CGColor;
_scanRectView.layer.borderWidth = 2;
CGAffineTransform captureSizeTransform = CGAffineTransformMakeScale(320 / self.view.frame.size.width, 480 / self.view.frame.size.height);
self.capture.scanRect = CGRectApplyAffineTransform(self.scanRectView.frame, captureSizeTransform);
}
- (void)viewDidLoad
{
[super viewDidLoad];
}