UIWebView modal YouTube player “Done” button action

前端 未结 3 1659
悲&欢浪女
悲&欢浪女 2020-12-31 16:45

In my iPhone app, I\'m presenting a modal view controller from a home screen with a UIWebView that displays an \"inline\" embedded YouTube video using this:

         


        
相关标签:
3条回答
  • 2020-12-31 17:17

    I'm not sure but it seems that after the "done" button is pressed and the Player is closed the control returns to the root view controller, in your case that's your first screen.

    For exaple in my application I have an UITabBarController as my rootViewController, in my AppDelegate I have something like this:

    self.window.rootViewController = self.myTabBarController;
    

    So that's the reason why my tabBarController (my first screen) always was presented after pressing the "done" button.

    I solved this setting my Modal View as my rootViewController after presenting it.

    Try this after presenting your modal view:

    MyAppDelegate *appDelegate = (MyAppDelegate *) [[UIApplication sharedApplication] delegate];
    [self presentModalViewController: myModalViewController animated: YES];
    [self.appDelegate.window setRootViewController: myModalViewController];
    

    NOTE: After dismissing the modal view you must restore the root view controller doing

    In my case:

    self.appDelegate.rootViewController = self.appDelegate.myTabBarController;
    

    Hope it helps

    0 讨论(0)
  • 2020-12-31 17:18

    Not an exact solution but a kind of patch can may be help you out.

    Take a global flag (may be in ApplicationDelegate) and set it to true when ever you tap on Done button on the youtube page. And in the very first controller viewWillAppear check if the flag is TRUE then present the second controller and turn the flag FALSE again.

    Hope it helps.

    0 讨论(0)
  • 2020-12-31 17:27

    The answer re: "I solved this setting my Modal View as my rootViewController after presenting it." is the correct approach. If you call youtube from a modally presented view controller it will return to the original controller which presented the modal one. If you then try to re-present the correct controller using flags it gets really messy and there can be timing issues. Izaakcito's method works properly.

    0 讨论(0)
提交回复
热议问题