Modal display of UIViewController from Juce - rotation


#1

Hi Folks,

Can anybody suggest how to get around this problem?

I create an instance of AVPlayerViewController, and display it from the Juce UIViewController instance using presentViewController.

All is good. Works fine when launched in Portrait, works fine when launched in Landscape.

However, when I rotate the app with the AVPlayerViewController visible, the AVPlayerViewController instance doesn’t resize in response to rotation.

When I try this from a non-Juce app, everything works as I’d expect (i.e. AVPlayerViewController rotates in the expected way).

I’ve tried all sorts of approaches to this, including use of a parent UINavigationController instance etc., but none of them have worked … hence the question. I suspect that this isn’t going to be specific to AVPlayerViewController…

Thanks in advance to anybody who can suggest a solution,

Pete


#2

For the record, the best I’ve been able to do is subclass AVPlayerViewController, and override shouldAutorotate to return NO…


#3

I can confirm that the same problem occurs with any UIViewController I create and display modally from Juce.

Pete


#4

Have you tried using autoresizesSubviews property of UIView? Have a look at how we did it in juce_ios_FileChooser.mm:

    void parentHierarchyChanged() override
    {
        auto* newPeer = dynamic_cast<UIViewComponentPeer*> (getPeer());

        if (peer != newPeer)
        {
            peer = newPeer;

            if (auto* parentController = peer->controller)
                [parentController showViewController: controller.get() sender: parentController];

            if (peer->view.window != nil)
                peer->view.window.autoresizesSubviews = YES;
        }
    }

#5

Hi Lucasz,

You are a genius - I can’t believe I didn’t think to try that. It was very kind of you to point-out to me - much appreciated - sorts my problem out!

If I could make a related suggestion to the backlog - could you consider creating the main UIViewController such that it is owned by a UINavigationController? In the viewWillAppear, just make sure you hide the navigation bar. Reason? It’d make it much cleaner to add child UIViewController elements that sit outside of the Juce codebase.

With best wishes,

Pete


#6

Weirdly, I found that with some of the child UIViewControllers, I had to implement this as well:


  open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)
    
    coordinator.animate(alongsideTransition: nil, completion: {
      _ in
      
      self.view.frame = CGRect(origin:self.view.frame.origin, size: size)
      self.view.setNeedsLayout()
    })
  }

Additionally: when using both a UINavigationController and a child UIViewController - I actually required the above in a custom UINavigationController!

All a bit crazy, really. But I hope it helps somebody!

Pete