cruffenach / CRToast

A modern iOS toast view that can fit your notification needs
MIT License
4.16k stars 464 forks source link

CRToastViewController doesn't follow the main window's supportedInterfaceOrientations #144

Open bas-tard opened 9 years ago

bas-tard commented 9 years ago

Hello,

Basically, I have an app that supports iPhone 6+'s landscape mode. Therefore my info.plist iphone orientation are all of them. My root view controller then implements supportedInterfaceOrientations to say all or just portrait.

Unfortunately, for iPhones other than the 6+, it means that the status bar will go to landscape when the rest of the app stays in portrait.

Fortunately, I've also figured out a solution, add the following to CRToastViewController:

- (NSUInteger) supportedInterfaceOrientations
{
    UIViewController* root = [UIApplication sharedApplication].delegate.window.rootViewController;
    if (root) {
        return root.supportedInterfaceOrientations;
    }

    return [super supportedInterfaceOrientations];
}
Ashton-W commented 9 years ago

Good job, thanks. Did you want to open a PR?

bas-tard commented 9 years ago

I could, but I've taken a look at the code (after a crash course in cocoapods!).

I did a quick test with the demo app and it didn't work. The reason is that my supportedInterfaceOrientations method used the view controller, which is a plain old UINavigationController and not the MainViewController, which is the root of the nav controller.

Long story short, there are multiple ways where the method I posted would not work: UISplitViewController, UINavigationController, UISplitViewController, etc.

I think the better solution would be to add a new kCRToast___Key value and link to CRToastViewController's supportedInterfaceOrientations.