简体   繁体   English

关闭UIPopoverController后呈现视图控制器

[英]Presenting a View Controller after a UIPopoverController is dismissed

I am having some difficulty presenting a full screen View Controller (specifically, an MPMoviePlayerViewController ) immediately after dismissing a UIPopoverController . 我在解散UIPopoverController之后立即呈现全屏视图控制器(特别是MPMoviePlayerViewController )时遇到了一些困难。 Essentially, I have a race condition and I'm not sure if there's an accepted best practice to correct it. 本质上,我有比赛条件,而且不确定是否有公认的最佳做法来纠正它。 Here is the code I started with: 这是我开始的代码:

   [[self searchPopoverController] dismissPopoverAnimated:YES];

   MPMoviePlayerViewController *player = [[MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:[video videoURL]];
   [[player moviePlayer] setFullscreen:YES animated:YES];
   [self presentMoviePlayerViewControllerAnimated:player];

The problem is that the popover doesn't actually dismiss before the next lines of code are executed, resulting (as expected) in an "Attempt to present [a view controller] while a presentation is in progress" warning. 问题在于,在执行下一行代码之前,弹出窗口实际上并没有消除,从而(按预期)导致“在演示过程中尝试呈现[视图控制器]”警告。 Somewhat humorously, the video does start playing (you can hear the audio), but the view controller is not presented so you cannot see the video. 有点幽默,视频确实开始播放(您可以听到音频),但是未显示视图控制器,因此您无法观看视频。

I've tried fixing this in several ways. 我已尝试通过几种方式解决此问题。 The only reliable solution I have found is ugly and not a guaranteed fix: 我发现的唯一可靠的解决方案是丑陋的,而不是可以保证的解决方案:

   [[self searchPopoverController] dismissPopoverAnimated:YES];

   dispatch_time_t start = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC));
   dispatch_after(start, dispatch_get_main_queue(), ^(void){
      MPMoviePlayerViewController *player = [[MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:[video videoURL]];
      [[player moviePlayer] setFullscreen:YES animated:YES];
      [self presentMoviePlayerViewControllerAnimated:player];
   });

Since UIPopoverController does not inherit from UIViewController , I do not believe there is any method for dismissing the popover that includes a completion-handling block. 由于UIPopoverController不能从UIViewController继承,因此我不认为有任何方法可以消除包含完成处理块的弹出窗口。 I've tried using NSInvocationOperation and NSOperationQueue , with no success, for example: 我尝试使用NSInvocationOperationNSOperationQueue ,但是没有成功,例如:

   NSInvocationOperation *invokedOperation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(playVideo:) object:video];
   [[NSOperationQueue mainQueue] addOperation:invokedOperation];

There are lots of existing questions that touch on this issue, but most seem to revolve around dismissing a UIViewController or subclass, for which dismissViewControllerAnimated:completion: is an obvious solution. 有很多有关此问题的现有问题,但大多数问题似乎都围绕着解散UIViewController或子类,而dismissViewControllerAnimated:completion:是一个显而易见的解决方案。

You should use the popover delegate method popoverControllerDidDismissPopover 您应该使用popoverControllerDidDismissPopover委托方法popoverControllerDidDismissPopover

This will notify you once the pop over has fully been dismissed. 一旦弹出窗口被完全消除,这将通知您。 https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPopoverControllerDelegate_protocol/index.html#//apple_ref/occ/intfm/UIPopoverControllerDelegate/popoverControllerDidDismissPopover : https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPopoverControllerDelegate_protocol/index.html#//apple_ref/occ/intfm/UIPopoverControllerDelegate/popoverControllerDidDismissPopover

为什么不实现UIPopoverControllerDelegate协议并将您的控制器添加为委托,那么您可以将第二个viewController从

-(void)popoverControllerDidDismissPopover:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UIPopoverController:关闭后更新视图 - UIPopoverController: update view after it is dismissed iOS /自动版式:取消已演示的控制器后,更改为演示视图 - IOS/Autolayout: Change to Presenting View After Presented Controller Dismissed WKWebView 操作表在被解散后解散呈现视图控制器 - WKWebView action sheet dismisses the presenting view controller after being dismissed 如果当前视图控制器发生更改,如何关闭模式视图控制器? - How can a modal view controller be dismissed if the presenting view controller is changed? 调用viewWillAppear时显示视图控制器的问题被解除 - Issue with calling viewWillAppear of presenting view controller when presented one is dismissed UIPopoverController没有在分配的位置显示控制器 - UIPopoverController is not presenting controller in assigned position 呈现MFMessageComposeViewController然后将其关闭后,呈现视图无法正确显示 - Presenting view not appearing properly after MFMessageComposeViewController is presented and then dismissed 登录后显示View Controller - Presenting a View Controller after login 在发送方视图控制器被解除后执行 segue - Performing segue after sender view controller is dismissed 编辑器视图控制器关闭后,UITableView不更新 - UITableView not updating after editor view controller dismissed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM