Sk.Azad Sk.Azad - 5 months ago 22
iOS Question

Support all orientation only for video player view controller in a portrait application

I have implemented this code in AppDelegate.m

-(UIInterfaceOrientationMask) application:(UIApplication *)application supportedInterfaceOrientationsForWindow :(UIWindow *)window
{
UIViewController *currentVC = [(UINavigationController *)[UIApplication sharedApplication].delegate.window.rootViewController topViewController];
if ([currentVC isKindOfClass:[VideoPlayerVC class]])
{
return UIInterfaceOrientationMaskAll;
}

return UIInterfaceOrientationMaskPortrait;
}


and pushing to the VideoPlayerVC with link like this :

NSURL *link = [NSURL URLWithString:strUrl];
VideoPlayerVC *vc = [[VideoPlayerVC alloc] init];
vc.videoUrl = link;
[self.navigationController pushViewController:vc animated:false];


This allows me to enable autorotate in the VideoPlayer ViewController but when the video playback ends in Landscape mode, the entire app is being converted into Landscape view mode only.

Please help me guys to fix the issue.
Thanks in advance.

Answer

The system only tries to invalidate your orientation when a full screen modal presentation happened or dismissed. So I suggest you to replace your [self.navigationController pushViewController:vc animated:false]; with [self presentViewController:vc animated:YES completion:nil];

And if your UE needs the navigation transition, you can try to mimic it with UIViewControllerContextTransitioning customization.

Also there is a tricky method if you must use push behavior(It's the only one method not using private api as I know) Every time you push/pop from the navigation stack, call the code below: [[vc presentViewController:[UIViewController new] animated:NO completion:^(BOOL completed){ [vc dismissViewControllerAnimated:NO completion:nil]; }]; The code try to make an invisible vc and dismiss it immediately to make iOS update the supported orientation.

Comments