I have a UITabBar with 2 bar items. The initial orientation of the device is portrait. If I rotate the device to landscape while being at tabBarItem2 the whole thing(Status Bar, TabBar, ViewContent2) rotates fine, but when I press the tabBarItem1 the ViewContent1 is still in Portrait. It also happens if I'm in tabBarItem1, then rotate device to landscape and I go to tabBarItem2.
I'm using the willRotateToInterfaceOrientation method on each view controller to move things.
I think this is happening because it is triggering the actual viewController's willRotateToInterfaceOrientation method and not on both of them.
Any ideas on how to fix that?
Both view controllers need to have
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Related
I have two viewcontrollers, ViewControllerA supports both landscape and portrait, click a button in ViewControllerA push into ViewControllerB, which supports landscape only, then I make the phone in the landscape direction and then pop back to ViewControllerA, by default A is in landscape mode now, but I want it to be portrait first in this situation. How can I implement that?
In your ViewControllerA's viewwillappear method set the orientation like
[[UIDevice currentDevice]setOrientation:UIInterfaceOrientationPortrait];
I am making a navigation based app and I need only portrait orientation except in a ZoomPictureViewController ( Zoom in, zoom out images) that supports all orientations.
I am presenting ZoomPictureViewController and returning YES in shouldAutorotateToInterfaceOrientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
But I get no rotation. I know that shouldAutorotateToInterfaceOrientation, willRotateToInterfaceOrientation, RotateToInterfaceOrientation are only get called on the current/visible view controller but this is not happening in my case. I have checked it via putting breakpoints and NSLog.
Are you using any type of Navigation Controller or a Tab View Controller? I've noticed that there are issues when rotating a UIView that's not the first or only view as a direct child of the main window.
So if your UIView is part of a Navigation Controller or a Tab View Controller, you'll also need to override shouldAutoRotateToInterfaceOrientation on the Navigation Controller or Tab View Controller.
Also I here's an important gotcha in the Apple documentation that might explain the problem you are having.
Tab bar controllers support a portrait
orientation by default and do not
rotate to a landscape orientation
unless all of the root view
controllers support such an
orientation. When a device orientation
change occurs, the tab bar controller
queries its array of view controllers.
If any one of them does not support
the orientation, the tab bar
controller does not change its
orientation.
I have an application which is focused around a bunch of viewControllers in portraitmode, but on a specific detail view i need to open another view if the device is rotated to landscape mode.
So the user will look at the information view in portraitmode and if the user then rotates the device to landscapemode then a new view is displayed with additional information. If the user rotates back to portrait then the added view needs to be removed so the "original" detailview is visible.
It's important that the "original" detailview is not rotated to landscape - Only open a new view in landscape mode.
I've tried using shouldAutorotateToInterfaceOrientation: and managed to have it open a viewController, but it's not being shown in landscape view so it looks all messed up plus I'm having some trouble getting the view to disappear when i rotate back to portraitmode.
How do i do this?
Check if the orientation has changed using the View controllers did change orientation methods and if its rotated to landscape add ur landscape view and when the device is rotated to portrait remove the view from the view controller's view.
in shouldAutorotateToInterfaceOrientation
if(UIInterfaceOrientation == UIInterfaceOrientationPortrait){
NewView *newViewController = [[NewView alloc]initWithNib:#"NewView" bundle:nil];
[self.navigationController pushViewController:newViewController animated:NO];
}
you can repeat this for all the other orientations as well.
Using shouldAutoRotate didn't work since the view that gets opened will be opened in portraitmode and not landscape.
I ended up with a solution using beginGeneratingDeviceOrientationNotifications and shouldAutoRotate in the subview.
I am making a TabBar based universal app. I have added few extra tabs and changed the viewController to navigationController. Now when i am trying to rotate the view from portrait to landscape, its rotating the inside view but tabBar does not rotate and it stays at the same place ie at the bottom of the portrait mode where as every other UI are rotating properly.
Make sure the controller not supporting the rotation (respectively its owner) overrides shouldAutorotateToInterfaceOrientation and returns YES for all orientations.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
#pragma unused(interfaceOrientation)
// Overriden to allow any orientation.
return YES;
}
http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW23
I have an application that consists of a login, 3 tables, and then an image.
You can rotate the image to landscape mode but what I want to be able to do is when the 'back' button is pushed and the app returns to the previous screen, I was the app to automatically rotate to give a portrait view.
Is there any way of doing this?
For previous controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
return YES;
}
return NO;}
If the previous view controller only supports portrait (see shouldAutorotateToInterfaceOrientation:) then it should automatically rotate.
If the previous view controller supports landscape but you want it to rotate to portrait if it was originally in portrait, you can probably force it by changing what shouldAutorotateToInterfaceOrientation: returns when navigating back. I wouldn't recommend this; it's inconsistent UI (and it's a bit tedious to figure out what navigation is going on).
There are various ways to set the view controller interface orientation (-[UIDevice setOrientation:] will attempt to trigger an autorotation), but then you're into the realm of private APIs and potential rejection.
Override shouldAutorotateToInterfaceOrientation: in your table view controller and only return the orientation you want.
This might not actually switch back the orientation, so if this alone doesn't work you might have to call setStatusBarOrientation:animated: on UIApplication in your table view controller's viewWillAppear: or viewDidAppear: methods.