I need to implement both variants of my Portrait orientation in iPad app.
I am using the code shown below to implement both Portrait and PortraitUpsideDown orientations.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
But orientation does not change when Orientation is PortraitUpsideDown.
What could be wrong?
Got it working.
Added both the variants of Portrait Orientations to Supported Interface Orientation to my info.plist for my app.
This has worked for me.
Hope this helps everyone.
you could use
return UIDeviceOrientationIsPortrait(interfaceOrientation)
which is just a macro for what you're trying to get.I'm not sure both will work on simulator.
Related
I want my app to be landscape. I tried everything, my storyboard's orientations are landscape, I changed the supported orientations and the initial orientation in info.plist. Can anyone help me?
In iOS 6 simulator it is landscape.
In iOS 5 you need to implement the following method in everyone of your view controllers.
// Called only in IO 5 and earlier.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft );
}
And set UIInterfaceOrientation "Initial interface orientation
" to UIInterfaceOrientationLandscapeRight in your Info.plist
And lay out your views in landscape mode.
Per Apple's developer docs
I know this has been asked before and I actually searched through the questions to make sure I was doing things correctly. My app needs to maintain portrait orientation so I want to disable it from rotating into landscape.
In the summary I have supported device orientations of portrait and upside down only.
In viewcontroller I have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
I have 6 other viewcontrollers, in each of them I have the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
But when I test the app on my provisioned iPhone, it rotates. Grrrr. What am I doing wrong?
Thanks
It's the same in the simulator.
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;
}
}
Although I know how to handle screen orientation in an iPhone application. Is there possibly a way we can ignore it?
Either by means of some code or may be setting it somewhere. For example in Android we can ignore screen orientation by making few changes. Is there some way in iPhone too?
If you don't implement or handle all the orientation then it should be oke:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
You app will only support portrait mode.
you can stop screen orientation by returning interfaceOrientation == UIInterfaceOrientationPortrait on shouldAutoRotateToInterfaceOrientation
Edited to be technically correct.
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.