I am trying to set a UIWindow in MainWindow.xib into landscape mode. Unfortunately, this option is greyed out in Interface Builder. I have a Navigation Controller within the same NIB that can be set to landscape, but this ends up looking awkward in Interface Builder, as the Nav Controller is set to landscape but the containing window is in portrait.
What's worse is that I can't get the window to run in landscape during runtime. I have this code in the view within the nav controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
I don't know how to specify this for the containing window though. I have set the orientation in the plist but this doesn't seem to make my view display in landscape.
From what i can see, it seems like you want your first view controller to be in landscape mode, when displayed.
For this, you need to set the "Initial orientation" in your info.plist file. There is a key for this.
Thus, what you need to do is, Make your xib in landscape mode, implement the method as you have done above and set the initial orientation to landscape in plist.
I faced a problem with the UIWindow being forced into portrait mode as well. My solution was to use another view level between the window and the views I was manipulating. Though not a perfect solution it worked. I hope you get it worked out.
Related
I'm building a more or less complex app, but I'm quite new to this. I've created my own ABCViewController, which works fine with the MainWindow.xib (also in landscape mode), but now I want to create a UITabBarController (without code) which should be shown up before the ABCViewController. I simply tried using the storyboard, but when I run the app, the UITabBarController is in Portrait. The attributes inspector in storyboard is set to landscape for all my view controllers. Is it possible to edit the shouldAutorotateToInterfaceOrientation method for the UITabBarViewController, which exists only in storyboard? I've also set everything to landscape in the Info.plist!
EDIT: Solved. I created the Vvew controllers which are shown in the tab bar controller, and then I used the shouldAutorotateToInterfaceOrientation method and returned YES (not (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)) in every view controller.
I have a UIViewController with IBOutlets linking to several UIViews. Various buttons switch between the views, but there are issues when I set a new view for the controller. Both the controller and the views are in landscape orientation, but after the first couple of switches some of the views display in portrait mode. What might be causing this?
You should check that all your UIViewControllers implement method shouldAutorotateToInterfaceOrientation. This method tells the operation system in what positions (orientations of screen) the UIViews controlled by that UIViewControllers could be displayed.
If you want all your views be displayed only in landscape orientations, then that method should return YES only for interfaceOrintation == UIInterfaceOrientationLandscapeLeft or interfaceOrintation == UIInterfaceOrientationLandscapeRight. if you want only portrait orientations then interfaceOrintation == UIInterfaceOrientationPortrait.
For example (support only landscape modes) :
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
And you should check that in your project settings you set appropriate Supported Device Orientations (also known as Supported interface orientations).
I think you should set the views to landscape mode in IB. If this is already done then I would suggest not changing the view controller's view explicitly. Implement a method, which can change the views.
In more detail:
Set a view as your view controller's view then every other view should be the subview of this view. You can make the change by removing the presented view and adding the new view or another method to implement the view changing is to add all view's in IB as a subview, hide all views then when you would like to change unhide the desired one and hide every other.
I hope you understand my approach, if not then I am here to answer your questions.
This way is easy to implement. :)
Check that you have this method enabled in all views:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Also, is it what you see on the simulator or on your device?
This may be a Simulator bug, but try using separate objects of UIViewController for each view, instead of one controller for all views. Personally, I haven't experienced any difficulty with orientation before, but I do things programmatically. I recommend that you do the same (you may NOT need to convert all your program's xib files, but maybe just the one you're having problems with). Just make sure that all UIViewControllers that you're using for that view to have the:shouldAutorotateToInterfaceOrientation set up appropriately and things should work just fine.
Hope this helps.
I have an app for the iPad/iPhone and Portrait and Landscape is working just fine. However, I recently added a TabViewController and a second tab with a view. Problem is when I click my second view and rotate and then switch back to the first view my controls are not repositioned
Can anyone tell me what I need to do so that I can reposition my views when the first view is clicked?
incidentally, I am assuming I will have the same problem the other way too... view 2 to view 1.
Did you checked that all your view controller implement this method ?
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
From my experience, the same problem also occurs with navigation controller. I guess that the framework wont send the rotation event to every hidden VC on purpose to save processing time. The solution I ever did is just overriding viewWillAppear and correctly layout subviews there if needed.
Quick problem:
I have an UITabBarController with 2 navigation controllers [lets call them Left and Right Controller]
On the default selected Left Controller I can push a new View Controller that detects interface orientation.
On the Right Controller I can push the same View Controller but it won't detect interface orientation, or for that matter, It won't even go into the shouldAutoRotateInterface method at all T___T
Haaalp!!
If it is of any relevance, the View Contoller that I'm pushing use the hidesBottomBarWhenPushed property.
Most likely this is your problem:
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.
The solution is to override the following method on every view controller leading to your view:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
return YES;
}
For example, instead using the default UITabBarController in IB, replace it with your own subclass containing just the method above.
I'm a bit late to the party on this, but I ran into a problem with autorotation at startup for a tab bar app I wanted always to run in portrait.
The app's plist has the necessary settings to both start in and only allow portrait mode, and all my view controllers only allow portrait mode. Yet, when I started the app holding my iPhone in landscape, the app started in portrait, but then rotated to landscape!
Rather than subclass UITabBarController, I simply overrode UITabBarController's shouldAutorotateToInterfaceOrientation: method using a category on class UITabBarController. I included this code in my app delegate:
#implementation UITabBarController(UITabBarControllerCategory)
-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
Works beautifully, and is quite lightweight.
does your uitabbarcontroller implement the auto rotate? any child viewcontroller that wants to implement autorotate has to have its parent implement autorotate.
All my app is in landscape mode .In some point I switch to a screen with Tab Bar Controller , but it's been placed like in portrait mode.I subclassed the UITabBarController and override the method "shouldAutorotateToInterfaceOrientation" to return YES always but because the app is already in landscape , this method is not being called.
does anyway have an answer to this?
thanks
Giald
You shouldn't have to subclass UITabBarController. The tab bar will autorotate to landscape, if all it's subviews support landscape. Just make sure all tabs support landscape orientation and you should be fine afaik.
Rengers is right, just make sure all tab views have YES in their respective shouldAutoRotateToInterfaceOrientation overrides. Depending on how you setup your app, check if any parent views have the shouldAutoRotateToInterfaceOrientation overrides. If so, it might be worthwhile commenting them out and leaving the overrides for the tab views only.