iOS application's orientation remember? - objective-c

I have several view controllers, which maintains only landscape mode and one view controller with all interface orientations(for example, slideshow). "Splash screen" can only in landscape mode. After "slideshow" is in portrait mode and I fully terminate application(from task bar too), application starts a "splash screen"(what should in landscape mode) unexpectly in portrait. But why it happens, if splash screen is actually not rotates in portrait if device rotated? And how to resolve this problem? Thanks.

In your SplashScreenViewController write:-
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

Related

How to fix a viewcontroller's rotation?

My app uses landscape only. I fixed it via .plist's Supported interface orientations.
However, I need to use UIImagePickerController, and it only supports portrait mode. How can I rotate my app's rotation to portrait in a specific viewcontroller?
Any tips will be very helpful! Ty!
See the blog post iPhone programming: How to force your app to run in landscape mode.
ColinE, Do you mean that I should set as below?
All other viewControllers
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || UIInterfaceOrientationLandscapeLeft);
}
and set the portarit page
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

ipad rotation in iphone project

I've created a project that is targeted just for iPhone (for now) and I chose supported orientation only Portrait. On iPhone it works great, but when I launch my project on iPad my application is rotating! Actually I tried to make it a universal app and in iPad deployment info I chose supported orientation only Portrait, my app still rotated on iPad. How may I fix that?
To only support Portrait mode in your view, implement the following in each of your views:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Also, you need to make sure that have set the Supported Device Orientations for each device as well:
You can manually set the rotation values in the view controllers by implementing this function:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait;
}

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

Interface Orientation won't change to Landscape on App Launch

i stuck on a problem that drives me crazy!
I have an iPad application starting with a TabBarViewController. Every Tab has it's own ViewController and nib-file.
To make interface orientation possible I added all orientations to my info.plist and subclassing my TabBarController to set:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Every View is autoresized and formatted well for displaying the right Orientation if I rotate the Interface. If I test it in the simulator, everything looks fine and I can rotate between the Orientations.
Now the point that drives me crazy:
If I launch the App in Portrait Mode, all works fine.. but if I launch in Landscape, I get an error and my Interface orientation seems still to be Portrait, while the Simulator is in Landscape Mode!!
The Error:
2011-05-24 21:50:15.011 Project[57995:207] Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.
I checked for Orientation like this:
-(void)viewWillAppear:(BOOL)animated{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) {
NSLog(#"Orientation: Landscape");
}
else{
NSLog(#"Orientation: Portrait");
}
}
The Log says it is in "Landscape" Mode if I launch in Landscape, but if I change tab to another it looks terrible because the View is displayed in Portrait mode instead.
On change back to the start-view where i asked for Orientation… the log displays "Portrait"… but the Simulator is still Landscape!
I can't figure out why the Orientation is Portrait on start,…
even if I start in Landscape…
Any idea how to solve this problem?
Ok. So the documentation says viewWillAppear: is called prior to all animations. And when your app starts, its initial orientation is Portrait. Based on what your orientation is, it then rotates to that orientation. Since it animates to the orientation off screen, this must be called after viewWillAppear:/ So when viewWillAppear: is called, its still in Portrait. I tested this myself.
I solved the problem!
Simply used this in viewWillAppear method of all my Views, to make it work when started in Landscape mode:
if(([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeLeft) || ([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeRight)){
//Landscape View
}
else{
//Portrait View
}
Works fine for me!

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.