ObjC - Automatic View Rotation - iphone

My fellow students and me coded a objective-c program for iPhone.
But we have a big problem:
Our App is coded in Portrait-mode, but 2 or 3 Views should be displayed in Landscape-mode (directly).
We activated Landscape autorotation in these views, but, if we open one of these views now, we get Portrait again and it only turns into Landscape, when we turn the device.
(Already on our test-device, no problem of the IOS-simulator!)
Can anybody help us please?

The only thing that worked for me was using
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
in my ViewController and presenting it with presentModalViewController.
This forces the View to stay in landscape.

Related

App Rotating Even Though I Told it Not To

Wrote an app with Xcode. Clicked the buttons that restrict orientations to be the two portrait options. Changed the plist file to only allow the two portrait orientations. Put the restriction in programatically.
When I build the app to my phone, it rotates into both landscapes and the upright portrait orientation. What the heck?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return ((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
The method you're using is part of the controller class, but that method may never get called if the controller class is either not active or not in control of the view on the screen. So your app might be auto rotating because this message is in fact never actually getting called. The solution is to check the connections or initializations of your view controller class to make sure that they are running as you expect.

Locking the orientation in an iPad app (plist or UIViewController?)

I'd like the app to work like it would be as if I locked the orientation manually. I'm trying to find how I can lock the orientation for an app. In the info.plist, I have this setting:
Supported interface orientations (iPad)
Item 0 Landscape (right home button)
Item 1 Landscape (left home button)
I thought that would be enough to keep my viewControllers from staying in landscape mode and not portrait. But it does not. Do I need to do
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
in ALL my viewControllers? Thanks!
All though implementing shouldAutorotateToInterfaceOrientation in all your view controllers will work, it is probably not the fastest or most practical way of doing what you are trying to accomplish.
If any of your view controllers in your hierarchy do not conform to the orientation change, then iOS will stop trying to rotate them. What this means is that only your root view controller needs to have implemented shouldAutorotateToInterfaceOrientation with only landscape orientations. Each view controller pushed or added will conform to that function.
I have had to do this in several of my apps and it was required for several reasons.
In the end and after a lot of testing, we determined that the condition has to be set on the info.plist AND on every viewController.
So make sure it is set on the plist and that every shouldAutorotateToInterfaceOrientationonly returns yes for the allowed orientation.
This is because the plist will help you with allowed LAUNCH orientations, but your app could still rotate afterwards, specially when using modal views.
You can download one of my free apps that does thins on iPad: http://itunes.apple.com/mx/app/hoteles-city/id471505865?mt=8
Yes you do.
I have a different solution however. In every UIViewController, I use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
} else {
return NO;
}
}

Xcode 4 component orientation problem

I'm using xCode 4 for my project which should work both on iPad and iPhone. So, i have created Universal windows based application. I want my application starts into landscape mode so i added following:
in method:
shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
I set interfaceOrientation == UIInterfaceOrientationLandscapeRight
and added the key into application.plist:
Initial Interface Orientation and set it on Landscape (right home button).
Now, the application did start in landscape mode, however, every component in it (button, label) remains rotated 90 degrees (counterclockwise).
When i load xib, Window orientation is set into Portrait and dropdown is disabled.
anybody has idea what i'm doing wrong?
shouldAutorotateToInterfaceOrientation isn't asking you to set the variable (and will have no way of reading the result even if you do), it's a query as to whether the nominated orientation is acceptable. So you want:
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight) return YES;
return NO;
}
/* or: return interfaceOrientation == UIInterfaceOrientationLandscapeRight; */
The XIB is a separate issue; neither Interface Builder nor its replacement parts in Xcode 4 can see what you're doing in your code, so they shouldn't just decline to let you design in landscape mode. However, it's the view that is linked to the view member of the relevant UIViewController that you want to set the orientation on, not the window.

iOS sample "GLPaint" can't support orientations portrait, portrait upside-down

I'd like to support orientations portrait and portrait upside-down on Sample code "GLPaint".
What's code this app support orientations portrait and portrait upside-down?
Sample code "GLPaint"
http://developer.apple.com/library/ios/#samplecode/GLPaint/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40007328
this sample use Object window not subclass UIViewController.
I tried this code, but didn't work.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
return YES;
return NO;
}
i tried to modify the app to set up a view controller 2 patterns.
A:GLPaint add subclass View Controller.
B:New Project OpenGL ES Application add GLPaint.
Both were bad.
Currently, i don't know what wrong with the source code.
Put PaintingView into built view controller, it works well on my side.
View Controller can control interface direction.

iPhone - Landscape Only App

I am trying to make an app that will only be viewed in Landscape. I have looked up some tutorials (albeit older ones) and have done the following:
-set up the info.plist to include a key for uiinterfaceorientation
-in the main view controller I have set the frame to be 480 x 320
Now, the first screen loads up ok. Everything is where it should be and whatnot. However, if I click a button that is set to present a modal view controller nothing happens. Everything is linked and coded correctly but nothing happens when I press the button. Am I doing something wrong with trying to force landscape?
At it's basic, this question is a how do you effectively make an app that will only be in landscape mode? Thanks for any help.
You should only uncomment this method I show you below:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}