I want forcefully autorotate view from portrait to landscape mode in IOS 6. The view to be in landscape mode displays graphs. How can I achieve this ?
In your application’s Info.plist file, add the UIInterfaceOrientation key and set its value to the landscape mode.
you can set the value of this key to UIInterfaceOrientationLandscapeLeft or UIInterfaceOrientationLandscapeRight. for landscape orientations.
Override your view controller’s shouldAutorotateToInterfaceOrientation: method and return YES only for the desired landscape orientation and NO for portrait orientations.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Related
I want to show one view controller in both orientation in iPhone. And when the screen is opening the preferred orientation should be portrait only. Then according to the device orientation it'll rotate. I found some solution and the screen is rotating too. But when I'm entering the screen it is auto rotating to landscape and than I've to manually rotate it to portrait.
Is there a simple solution to this problem?
You should implement preferredInterfaceOrientationForPresentation and
supportedInterfaceOrientations like:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIDeviceOrientationPortrait;
}
//You don't actually need to implement this as UIInterfaceOrientationMaskAllButUpsideDown is the default for iPhone
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
In my application, supported orientations are Landscape Right & Landscape Left. Its single screen application. In ViewController I added following code to restrict orientation.
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
-(BOOL)shouldAutorotate
{
return YES;
}
My Problem is whenever app launches in Landscape Left. If device position Landscape Right, then app view rotate in 180 degree then app starts working in Landscape Right.
There is no issue if device position is Landscape Left.
Note: I am testing application on iPod 5.
EDIT:
After some observations, If you are supporting only Landscape (i.e Landscape Right & Landscape Left), then you will face this problem. Application will always open in orientation which listed first in plist (In my case that is Landscape Left).
I Closed this issue by removing Landscape Left orientation support. If any one have solution for this please share.
Thanks for help.
I had the same problem, setting the 'Initial interface orientation' to UIInterfaceOrientationLandscapeLeft in the plist didn't work, nor did returning it in preferredInterfaceOrientationForPresentation in the view controller.
What solved this for me is reordering the 'Supported interface orientation' array in the plist to have my desired initial orientation as the first item in the array.
Did you checked the orientation settings in your General settings of the project in XCode.
Replace your method shouldautotrotatetointerfaceorientation to
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
I am developing an iPhone only app. This application supports portrait and landscape orientations in the Supported Interface Orientations, but in the first view of the application I disable rotation with the following code:
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Now, my problem is that when I start the app on an iPad with iOS 6.1 while holding the iPad in landscape mode, the app starts in portrait mode while the status bar is in landscape mode. Also, the application does not respond to any touches.
I have tried returning YES in the call to shouldAutorotate or setting the status bar in portrait mode with a call to [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait], BUT when I do this the application switches 3 times in orientation (landscape -> portrait upsidedown -> portrait) resulting in a lot of flickering at start-up, so this doesn't seem like the way to go, or is it?
What you have in AppDelegate function
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ }
By default, an app and a view controller’s supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.
Check for selected viewcontroller in supportedInterfaceOrientationsForWindow function and then set it to Portrait orientation.
my app has been working fine until I've tried making some changes using the ios 6 SDK
The app runs in portrait mode 99% of the time. This has been constrained by only allowing portait mode to be available in the info.plist
There is one view controller which needs to be shown in landscape mode. This is achieved "manually" by simply rotating the view by 90 degrees, like so:
self.view.transform = CGAffineTransformMakeRotation(3.14159/2);
This still works fine in iOS 6.
However, this view controller has some text fields. When the user taps one it shows the keyboard. Since I've only rotated the view (and not actually changed the orientation of the device), the keyboard comes out in portrait mode, which is no good.
In previous versions of iOS, I set the orientation of the status bar to be landscape, and as a byproduct, this would set the keyboard to be landscape as well, like this:
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];
However, this has stopped working for iOS 6.
I have read a million stack overflows trying to get this to work, but still have no luck.
Changing the keyboard orientation and transform is an difficult part and not a good solution(especially when it changes status bar orientations).
Better solutions is to allow application to support all orientations.
Implement the Orientation delegates inside your ViewControllers asper the rotation support.
For Supporting only Landscape
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationLandscapeRight ;
}
- (BOOL)shouldAutorotate
{
return NO;
}
For Supporting only Portrait
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
I have a very strange problem that I am as yet unable to diagnose.
In my iOS app (it's a universal binary), when I run on iPad 4.3, the orientation at launch is inconsistent.
The app delegate adds a splash screen (UIViewController) to the main window, then removes it and adds the app's primary view. It is this primary view which is the issue - approximately half of the time, it loads up correctly in landscape orientation, the other half it loads the view in portrait (though both the status bar and keyboard are correctly in landscape).
I'm at a bit of a loss as to why the orientation at launch is changing, when I am making no changes to the code or the simulator/device orientation.
I have UIInterfaceOrientationLandscapeLeft and UIInterfaceOrientationLandscapeRight set as the only supported orientations for iPad in the Info.plist and every view controller is using the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// The device is an iPad running iPhone 3.2 or later.
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
}
} else {
// The device is an iPhone or iPod touch.
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
return YES;
}
}
return NO;
}
Can anyone help me out with this??
Cheers,
Olly
If the status bar and keyboard are always in landscape then the problem should not be in shouldAuto... method. It might be in viewDidLoad. Also, try the following: in project-info.plist, set "Initial interface orientation" as landscape left/right, "clean" the project and run.