按下主页按钮后重新进入时,Zbar扫描仪视图变为非活动状态

时间:2013-07-05 11:49:55

标签: objective-c ios6 zbar-sdk zbar

当我按下主页按钮后重新进入应用程序时,我的Zbar相机视图变为无效&摄像机视图中出现黑屏。我在控制台中收到一条日志消息。那就是:

ZBarReaderView: ERROR during capture: The operation could not be completed: An unknown   error occurred (-12785)

有什么想法吗?请帮帮我们在此先感谢您的帮助。

以下是代码:

- (void) Load_QR_Reader_View {


ZBarReaderViewController *reader = [ZBarReaderViewController new];

reader.navigationController.navigationBarHidden = NO;

reader.readerDelegate = self;

//settings button adding
reader.cameraOverlayView=[self customUI];

reader.readerView.torchMode = 0;

reader.showsZBarControls = NO; //for the cancel button & info button

NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
BOOL isOn=[defaults boolForKey:@"cameraView"];

if (isOn) {

    reader.cameraDevice = UIImagePickerControllerCameraDeviceFront;  //set the camera front or rear
}
else{

    reader.cameraDevice = UIImagePickerControllerCameraDeviceRear;  //set the camera front or rear

}


ZBarImageScanner *scanner = reader.scanner;


[scanner setSymbology: ZBAR_I25
               config: ZBAR_CFG_ENABLE
                   to: 0];

[self presentModalViewController: reader
                        animated: YES];

}

-(UIView *)customUI{

UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[view setBackgroundColor:[UIColor clearColor]];

UIImage *bottomimage = [[UIImage alloc] init];
bottomimage = [UIImage imageNamed:@"screen.png"];
UIImageView *image2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 321, 480)];
[image2 setImage:bottomimage];
[view addSubview:image2];

//adding a bar
UIImage *image = [[UIImage alloc] init];
image = [UIImage imageNamed:@"tab-bar-bg.png"];
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 247, 48)];
[iv setImage:image];
[view addSubview:iv];

//Add settings button
UIImage *img = [UIImage imageNamed:@"setting-btn.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
           action:@selector(settingsButtonAction)
 forControlEvents:UIControlEventTouchDown];
[button setBackgroundImage:img forState:UIControlStateNormal];
button.frame = CGRectMake(247, 0, 73, 48);
[view addSubview:button];

//Add a label over image
imageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 247, 48)]; //5 3 240 40
[imageLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:20]];
[imageLabel setTextAlignment:UITextAlignmentCenter];
[imageLabel setBackgroundColor:[UIColor clearColor]];
[imageLabel setTextColor:[UIColor whiteColor]];
[imageLabel setNumberOfLines:1];
[imageLabel setText:@"Codemen Solutions Inc."];
[view addSubview:imageLabel];

//add a label to show whether offlyn or not
connectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 65, 247, 21)];
[connectionLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:20]];
[connectionLabel setTextAlignment:UITextAlignmentCenter];
[connectionLabel setBackgroundColor:[UIColor clearColor]];
[connectionLabel setTextColor:[UIColor blackColor]];
[connectionLabel setNumberOfLines:1];
[connectionLabel setText:@"Offline Mode"];
[view addSubview:connectionLabel];


if ([self reachable]) {

    connectionLabel.hidden = TRUE;
}
else{

    connectionLabel.hidden = FALSE;
} 


//Add timestamp
timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(1, 375, 321, 30)];
[timeLabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:25]]; //DBLCDTempBlack
[timeLabel setNumberOfLines:1];
[timeLabel setBackgroundColor:[UIColor clearColor]];
[timeLabel setTextAlignment:UITextAlignmentCenter];
timeLabel.textColor = [UIColor blackColor];
[view addSubview:timeLabel];

[self GetCurrentTime];

[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(GetCurrentTime) userInfo:nil repeats:YES];


//add date
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setDateStyle:NSDateFormatterMediumStyle];

NSString *dateToday = [formatter stringFromDate:[NSDate date]];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(-5, 415, 325, 15)];
[label setFont:[UIFont fontWithName:@"Arial" size:15]]; //DBLCDTempBlack
[label setNumberOfLines:1];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextAlignment:UITextAlignmentCenter];
label.textColor = [UIColor blackColor];

[label setText:dateToday];
[view addSubview:label];


//settings label set
settingsLabel = [[UILabel alloc] initWithFrame:CGRectMake(6, 121, 290, 30)];
[settingsLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:20]];
[settingsLabel setTextAlignment:UITextAlignmentCenter];
[settingsLabel setBackgroundColor:[UIColor clearColor]];
[settingsLabel setTextColor:[UIColor blueColor]];
[settingsLabel setNumberOfLines:1];
[settingsLabel setText:@"For settings scan admin QR"];
[view addSubview:settingsLabel];

settingsLabel.hidden = YES;

return  view;

}

基本上我可以选择在这个应用程序中拍照。拍完照片后,我会回到扫描仪视图。然后,如果我点击主页按钮,重新进入应用程序后会出现此问题!

0 个答案:

没有答案