簡體   English   中英

ZBarSDK不要關閉viewController

[英]ZBarSDK don't dismiss the viewController

我在我的應用程序中使用ZBarSDK( http://zbar.sourceforge.net/iphone/ )。 它工作正常且非常快,但我發現了一個問題。 我在控制台中收到此警告,並且掃描儀viewController永不關閉。 僅當我嘗試掃描已經聚焦的條形碼時,它才會發生。 我的意思是,當我按下打開閱讀器viewController的按鈕,然后將相機聚焦在條形碼所在的位置時,它工作正常,viewController消失了,我得到了代碼。 但是問題是當我已經將iPad聚焦在條形碼上,然后按閱讀器按鈕時。 呈現了閱讀器viewController,我得到了代碼,但是未關閉viewController並得到了以下警告:

警告:在演示或關閉過程中,請嘗試從視圖控制器中關閉!

這是使用的代碼:

- (void)escanearCodigo
{
    ZBarReaderViewController *escanearVC = [ZBarReaderViewController new];
    escanearVC.readerDelegate = self;
    escanearVC.supportedOrientationsMask = ZBarOrientationMaskAll;

    // Presentar pantalla escaneo
    [self presentViewController:escanearVC animated:YES completion:nil];
}

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    // Obtener el resultado del escaneo
    id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        //Almacenar el codigo de barras
        break;

    NSLog(@"Code: %@", symbol.data);

    [reader dismissViewControllerAnimated:YES completion:nil];
}

我希望我已經解釋清楚了:)

提前致謝。

更新:到目前為止,最好的“半解決方案”是下一個:將didFinishPickingMediaWithInfo代碼放在if語句中,以防止在未提供viewController時執行該代碼(我認為):

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    if (![reader isBeingPresented]) {
        // Obtener el resultado del escaneo
        id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
        ZBarSymbol *symbol = nil;
        for(symbol in results)
            //Almacenar el codigo de barras
            break;

        [reader dismissViewControllerAnimated:YES completion:nil];

    }

}

...但是我需要聚焦另一個區域(沒有條形碼),然后聚焦到條形碼區域進行掃描。

由於該警告與ZBarReaderViewController的顯示和關閉有關,因此,您只dismissViewControllerAnimated:completion:調用封裝在if-else-block中。 這是為了防止您描述的ZBars性能受到影響。 另外,如果演示文稿尚未結束,您可以延遲通話。

例如:

if (![reader isBeingPresented]) {
    [self dismissReader];
}else{
    [self performSelector:@selector(dismissReader) withObject:nil afterDelay:0.7];
}

然后在[self dismissReader]

- (void) dismissReader
  {
      [_reader dismissViewControllerAnimated:YES completion:nil];
  }

注意 :0.7秒的延遲時間是任意的,並且可能會根據動畫的持續時間而有所不同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM