Orientation doesnt work when i add tabBarController in splitView - objective-c

In my app i have added tabBarController in split View's RootViewController.In that portrait mode works fine but it orientation doesn't change to landscape mode. Orientation doesn't change in landscape when i add tabBarController in rootViewController.
Please suggest me the way to do this.

Make sure that all your view controllers contained in the tab bar controller can be display in all orientations. see Technical Q&A QA1688 for more informations. https://developer.apple.com/library/ios/#qa/qa1688/_index.html
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

Related

How to setting orientation for each ViewController in Tabbed Application in iOS7?

In the Tabbed Application I have two View.
I want to fix the firstView to portrait and the seccondView can rotate to portrait and landscape.
I implement the code below in firstViewController.
- (NSUInteger)supportedInterfaceOrientation {
return UIInterfaceOrientationMaskPortrait;
}
The code in secondViewController is
- (NSUInteger)supportedInterfaceOrientation {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
But when I rotate my phone, the setting have no working.
Cloud somebody can tell my how to do that.
You need to subclass your UINavigationController and UITabBarController. Take a look at this questions, it is essentially the same shouldAutorotate, supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation does not work as expected in iOS 7

How to get rotation to work in iOS7?

I want my app to support landscape only (left and right) on iPhone and iPad.
Hence in the info.plist I added landscape as the supported orientations.
My root controller is a UINavigationController with one controller on its stack.
However, my controller also rotates to portrait but not to portrait upside down.
If I Add GetSupportedInterfaceOrientations() (supportedInterfaceOrientationsForWindow: in ObjC) to the app delegate and return landscape there, the rotation completely stops working.
How hard can it be?
Did you try to use?
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
hope this helps..
Figured it out. The topmost view controller has to return the interface orientations it wants to rotate to. In my case, that's the UINavigationController.
And the change was already in iOS6.

How comes this UIViewController is always displayed in Portrait Mode?

When my device is in landscape mode and I modally present a view controller, this is always displayed in portrait mode, which is what I want.
However, I don't understand why other views (modally presented) are always displayed in landscape mode instead (if the current orientation of the device is landscape). The code I use is the same for all my view controllers, and the xib file orientation property is always Portrait.
This is how I push the view controller which works (it is never displayed in landscape mode):
- (IBAction)showImport:(id)sender
{
CMImportExportViewControlleriPhone *importController = [[CMImportExportViewControlleriPhone alloc] initWithNibName:#"Import-Export-iPhone" bundle:nil];
[importController setLayoutViewController:self];
//[importController setDelegate:self];
[self presentModalViewController:importController animated:YES];
[importController release];
}
thanks
If this is initial view controller and you have settings in plist file to start application in portrait mode then it would display in portrait mode doesn;t matter what is your device orientation. When you put your device in landscap mode and present new view controller, it will be landscap as it follows the status bar orientation! Before presenting new view controller try reseting status bar to portrait mode and then present new view controller. It will be presented in portrait mode! I had this similar issue in iOS 6.0.

iOS app - changing the orientation in tabbar

In my app I have a tabbar with 5 buttons. The total app has only portrait orientation and I have set it correctly.
My problem is that when I click the second button of the tabbar, the view appears normally in portrait but when the user tilts the device I want that particular view to be get changed to landscape. Is it possible to change the tabbar position to landscape and when the other buttons are clicked all to be changed to portrait?
Else while it is tilted I have to show the view alone in landscape without the tabbar, how can I do this?
So, to be clear, you want the entire app and all views in portrait EXCEPT for the view triggered by the second tab bar button, which you want to always appear in Landscape?
if I've not confused your question, than just put the following line of code in the "viewDidLoad" method of the controller of view number 2
self.view.transform = CGAffineTransformMakeRotation(M_PI / 2);
You probably want to bite the bullet and let your project accept multiple orientations at its highest level and then decide per UIViewController which orientations are supported. This will allow the frameworks to take care of a lot of the work for you (always a good idea).
In each view's controller, override this method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
You will want to return YES for any orientation that you want the view to support.
The four options for the interfaceOrientation parameter are:
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
So for your case, you will want the view controller hosting your view and tab bar to support all of the orientations. This is how the function would look:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return YES;
}
But for a extra detail, if you wanted to support only Landscape Left and Portrait Upside Down orientation, the function would look like this:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
A UITabBar only supports rotation, if the ViewControllers of all tabs return YES at shouldAutorotateToInterfaceOrientation.
You could achieve what you want, if you let your "portrait" tabs check if they are visible (via
tabbar.selectedViewController
or
tabbar.selectedIndex
and only reply yes when they're not selected.
The user experience could be confusing though, when the user changes the tab in landscape mode
a portrait view is presented ...
try this w.r.t.: tabbar.selectedViewController
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeRight];

iPad Layout different only on launch

Ok I have an interesting issue on an iPad application I am developing.
When the app launches in portrait mode the layout works as expected. I rotate the iPad and the rotation works fine.
When the application launches in landscape mode there is additional white space appearing and the layout does not work as expected. But when I rotate the application to portrait it rotates just fine. It also lays out fine when I rotate it back to landscape.
What could be causing this problem? The view controller in question is a view controller that contains a UINavigationController (I had to add in a header). I wonder if it is something with UINavigationController.
Your view is expecting Portrait mode upon launch. In your view Controller, you need to let it know to look for orientation, and load the corresponding view.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight))){
self.view = landscape;
}else if(((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){
self.view = portrait;
}
return YES;
}
Ok so what was strange in my application is that the layout would become correct when the tab controller switched tabs back to the view that was being funky. So, I added a hack in order to switch between the tabs before the makeKeyAndVisible of the main window.
I did try your suggestion WrightsCS. The real reason it didn't work is because I'm loading UINavigationController's view in the sub view of the page, so I didn't really have control of the layout that was messing up. The top bar of the navigation controller was loading a little lower than it should have been.