0

標準のカメラ ロールの写真ピッカーを表示するために、presentViewControllerを使用しようとしています。UIImagePickerControlこれは、私のアプリのほとんどでエンドツーエンドで機能します。それが機能しない場所は、すでに提示されているviewController;内で imagePicker を使用したい場合です。アルバムを表示するビューを表示できません。

rootViewController基本的な考え方は、ウィンドウ オブジェクトまたはアプリ デリゲートの永続tabBarController化 (つまり) にアクセスしようとしているということですrootViewController。どちらも、できれば常に存在するトップ レベルのアイテムの例です。そうでなければ、「自己」を使用するだけでは、それを提示する部分的なビューになってしまいます。

presentViewController既にpresentedView内に信頼できる方法はありますか?

dispatch_async(dispatch_get_main_queue(), ^ {
    // 1. attempt that works well elsewhere in app
    [((AppDelegate*)[[UIApplication sharedApplication] delegate]).tabBarController presentViewController:self.imagePickerController animated:YES completion:nil];

    // 2. this does nothing, no crash or action  (_UIAlertShimPresentingViewController)
    [[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:self.imagePickerController animated:YES completion:nil];

    // 3. attempt off related internet suggestion, nothing happens
    UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
    while (topController.presentedViewController) {
        topController = topController.presentedViewController;
    }
    [topController presentViewController:self.imagePickerController animated:YES completion:nil];

});
4

1 に答える 1

0

はモーダル表示を意図しているためpresentViewController、同じ で同時に 2 つ目のモーダルを表示することはできないと思いますUIWindow。ただし、新しいUIWindowを追加してそこに表示することはできます。

originalWindow = [[[UIApplication sharedApplication] keyWindow];
tempWindow = [[UIWindow alloc] init];
UIViewController *controller = [[UIViewController alloc] init];
tempWindow.rootViewController = controller;
[tempWindow makeKeyAndVisible];
[controller presentViewController:self.imagePickerController animated:YES completion:nil];

画像ピッカーのリターンへの応答に、次のようなものを追加する必要があります。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  // Process the result and then...
  [self cleanupWindow];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
  [self cleanupWindow];
}

- (void)cleanupWindow {
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(madeKeyWindow:) name:UIWindowDidBecomeKeyNotification object:nil];
  [originalWindow makeKeyAndVisible];
}

- (void)madeKeyWindow:(NSNotification *)notification {
  [tempWindow removeFromSuperview];
  tempWindow = nil;
  [[NSNotificationCenter defaultCenter] removeObserver:self name:UIWindowDidBecomeKeyNotification object:nil];
}
于 2014-10-06T20:34:45.190 に答える