Reputation: 149
i have a tabbar ios app. i want to make one of the tabs portrait only. how do i do that? i already tried the solution in How to force view controller orientation in iOS 8? and didn't help. I put that in view controller's .m code. This view controller has both a UIView and UITableView in it. pl see image below;
thank you.
Upvotes: 1
Views: 360
Reputation: 1097
in your all viewcontroler write this code:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll; //allow rotate landscape, portrait
}
and write this code in in which viewconroller you want only portrait.
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown; // portrait only
}
OR you can use this one:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([self.window.rootViewController.presentedViewController isKindOfClass: [CompareViewController class]])
{
CompareViewController *compareController = (CompareViewController *) self.window.rootViewController.presentedViewController;
if (compareController.isPresented)
return UIInterfaceOrientationMaskLandscape;
else return UIInterfaceOrientationMaskPortrait;
}
else return UIInterfaceOrientationMaskPortrait;
}
Upvotes: 1
Reputation: 4749
Try to create extension of UITabbarController, and then override below 2 methods in extension:
supportedInterfaceOrientations
shouldAutorotate
And in both the methods:
just validate,
if self.selectedIndex = 'particular index'
(the tab index, which you want portrait) and return accordingly.
Upvotes: 0