make one tab of ios tabbar app portrait orientation only - ios

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.

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;
}

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.

Related

Universally lock the orientation of MKMoviePlayerController to landscape mode only

How to use MPMoviePlayerController to play video in landscape orientation in iOS all across the Application. I am using the MPMoviePlayerController in many viewControllers of my app and I want all the MKMoviePlayerController torun only in landscape mode irrespective of the orientation of the parent view controller from where this ViewController is called.
Enable landscape orientation in your project settings.
Subclass UIViewController and in your new subclass (e.g. MyViewController) add these callbacks:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
Make all your view controllers of type MyViewController.
In the views you want to force landscape override those methods with:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeRight;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}

ios 7 orientation issue

In my App (deployment target iOS 7) for showing Pictures using Navigation Controller with root view controller (support portrait only)
[ pushes —> ]
Image view controller (support portrait & landscape)
In this image are shown using page View Controller
[ then presents —> ]
MPMovieplayer(support portrait & landscape)
on dismiss from movie player and popping to portrait only root view controller it turned to landscape.
I have given these in root view controller
-(BOOL)shouldAutorotate {
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
I need this controller not going to landscape at any scenarios..
i have handled the orientation in Image View controller using the delegates
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
}
In Image view controller like this
- (BOOL)shouldAutorotate {
return YES;
}
Finally I got this fixed on using this checking in Appdelegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
// Get topmost/visible view controller
UIViewController *currentViewController = [self.navigationController topViewController];
// Unlock landscape view orientations for this view controller
if([navigationController.topViewController isKindOfClass:[ImsgeViewController class]])
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else if([navigationController.topViewController isKindOfClass:[PageContentViewController class]])
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
// Only allow portrait (standard behaviour)
return UIInterfaceOrientationMaskPortrait;
}

Launching app in landscape distorts entire app, when disabling landscape orientation in certain controllers

I'm utilizing a navigation controller in my app. I want all of my viewController to be in portrait only except for one, which will support landscape.
Going with an accepted answer in Stack Overflow I subclassed my nav controller and include this code:
iOS 6 - Navigation Controller Landscape Rotations For Some Views While Others Portrait Only
- (BOOL)shouldAutorotate {
id currentViewController = self.topViewController;
if ([currentViewController isKindOfClass:[IssueViewController class]])
return YES;
return NO;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
This singles out the one view controller I would like to rotate. Everything works great except when I launch the app in landscape. The image gets crushed and off centered.
screen shots here: http://imgur.com/a/jyrJ2
Any suggestions on correcting this? Thank you!
Tested your code. This works fine only when you change the orientation, but it doesn't reflect changes according to current interface orientation if you launch the app in landscape or go from one to other controller in landscape.
Use the following approach, which I have used to solve same kind of issue some time ago.
Add this code in UINavigationController subclass
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
And in you ViewController, add this code
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
//Control UIInterfaceOrientationMask here to tell which interface orientations you want to support for this ViewController
return UIInterfaceOrientationMaskPortrait;
}

How to rotate one view controller and others stay in one mode (portrait mode) in ios?

I have five view controllers and In Project Target Device Orientation I have enabled Portrait ,Landscape Left and Landscape Right. Now I want 4 view controllers out of 5 view controllers Stay in Portrait mode (Not Rotate into landscape left and landscape right) and only one view controller rotate in all modes(Portrait,landscape left,landscape right). So How can do this please tell .
Implement -(NSUInteger)supportedInterfaceOrientations for each of your ViewControllers and specify which interface orientations each controller should support.
Edit
Assuming that you have a separate implementation for each of your ViewControllers, implement -(NSUInteger)supportedInterfaceOrientations and -(BOOL)shouldAutorotate in each of your implementations.
For example
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
will ensure that your view controller supports all landscape modes. Combine this with
-(BOOL)shouldAutorotate{
return YES;
}
and your display will "flip" over when rotated.
Use the enum UIInterfaceOrientationMask to adjust which orientations are supported and try different combinations of this along with a YES/NO return value to -(BOOL)shouldAutorotate until you get the behaviour you want.
First of all, in AppDelegate, write this.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAll;
}
Then, For UIViewControllers, in which you need only PORTRAIT mode, write these functions
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
For UIViewControllers, which require LANDSCAPE too, change masking to All.
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
//OR return UIInterfaceOrientationMaskAll;
}
Now, if you want to do some changes when Orientation changes, then use this function.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
}
NOTE Please :-
A lot depends on with which controller is your UIViewController embedded in.
Eg, If its inside UINavigationController, then you might need to subclass that UINavigationController to override orientation methods like this.
subclassed UINavigationController (the top viewcontroller of the hierarchy will take control of the orientation.) did set it as self.window.rootViewController.
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
From iOS 6, it is given that UINavigationController won't ask its UIVIewControllers for orientation support. Hence we would need to subclass it.

How to set AViewController (subclass of TabBar and Nav Controller) to portrait only

If I have AViewController which is a subclass of TabBarController and NavigationController, is it possible to set it to portrait? while, the other ViewController can rotate normally. (Portrait and Landscape)
Thank you
Yes it is. You can find the documentation here. You just have to override a few methods and return supported orientations for each view controller, such as supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation methods.
For example, to limit the orientation to portrait you would do
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return interfaceOrientation == UIInterfaceOrientationPortrait;
}
Edit:
I added the preferredInterfaceOrientationForPresentation method. Try this. This is the exact code i'm using in one of our apps, and it is working for us.

Resources