Odd iPad rotation effect - ios

I have a pretty standard iPad application that is setup to only be landscape. To affect this, I have set the initial interface orientation to landscape, and the support interface orientations to just the single landscape left home button, and also overridden shouldAutorotateToInterfaceOrientation properties to the following:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
BOOL b = UIInterfaceOrientationIsLandscape(interfaceOrientation);
return b;
}
The really odd thing is that when the app starts out, it is correct, and rotating the iPad upside down does nothing, but rotating with the home button down rotates the screen, but once rotated, it will never rotate back, so thinking this is something other than rotation settings.
Has anyone run into this before?

From the docs:
#define UIInterfaceOrientationIsLandscape(orientation) \
((orientation) == UIInterfaceOrientationLandscapeLeft || \
(orientation) == UIInterfaceOrientationLandscapeRight)
So if you want to support just ONE of the landscape rotations, this is not the way to go...

Related

Programmatically disable portrait orientation lock

In my camera app, everything works perfectly fine orientation wise. If portrait orientation lock is not enabled on a users phone, then everything works perfectly.
However, if a user has portrait orientation lock enabled and they record sideways, then the video gets recorded in portrait mode but everything is sideways inside the video.
Is there any way to check if portrait orientation lock is enabled or any way to get around this? Thank you.
There are a couple of things. You can override the shouldAutorotate function in the view controller that you are using the camera in like so:
override func shouldAutorotate() -> Bool {
return true
}
Then you could set it to false again once they are finished with the camera so it retains their device settings. Not sure if this is the best way, but is A way.
Another possible way that you might be able to get around this is to simply always check the device orientation. The device will still detect the physical orientation of the device even if the visual orientation of the UI doesn't autorotate (https://developer.apple.com/documentation/uikit/uidevice/1620053-orientation). So the following shows the possible device orientations, as per the Apple documentation (https://developer.apple.com/documentation/uikit/uideviceorientation)
enum UIDeviceOrientation : Int {
case Unknown
case Portrait // Device oriented vertically, home button on the bottom
case PortraitUpsideDown // Device oriented vertically, home button on the top
case LandscapeLeft // Device oriented horizontally, home button on the right
case LandscapeRight // Device oriented horizontally, home button on the left
case FaceUp // Device oriented flat, face up
case FaceDown // Device oriented flat, face down
}
Knowing those you can just check if the current orientation is one of those:
if (UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft ||
UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft) {
...override autorotate to true
}
These might solve your issue.
You can disable portrait orientation lock by using this method:
- (NSUInteger)lockorientation
{
return UIInterfaceOrientationMaskPortrait;
}

How to use UIInterfaceOrientationPortrait and UIInterfaceOrientationLandscapeLeft

I have a project whose rootViewController is a UINavigationController, and in my project only the view controller loading a full screen UIWebView. I need to change its orientation.
I have finished fixing the issue, but there's some trouble: When a user is in the view controller with the web view in the landscape orientation then clicks the back button, the previous view controller is also in landscape orientation. I want it to be in portrait, however. Any ideas on how to do this?
If you can read Chinese, I found this page, thanks.
implement
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
for whatever viewcontroller you require to stay in portrait.
I have try many solution, but the correct answer with working solution is:
ios 8 and 9, no need to edit info.plist.
- (BOOL) shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown);
}
possible orientation
UIInterfaceOrientationUnknown
The orientation of the device cannot be determined.
UIInterfaceOrientationPortrait
The device is in portrait mode, with the device held upright and the home button on the bottom.
UIInterfaceOrientationPortraitUpsideDown
The device is in portrait mode but upside down, with the device held upright and the home button at the top.
UIInterfaceOrientationLandscapeLeft
The device is in landscape mode, with the device held upright and the home button on the left side.
UIInterfaceOrientationLandscapeRight
The device is in landscape mode, with the device held upright and the home button on the right side.

How to get an iOS 7 iPhone app to rotate to all interface orientations?

I'm working on an iPhone app. Right now all my view controllers rotate to portrait, landscape left, and landscape right (default behavior for an iPhone app out of the box). What I want is for my app's setup, app-wide, to include support for all interface orientations. How do I make that happen? I have all interface orientations selected at the project level and it's not making any difference. Here's a pic:
Now, when I test my app on my iPhone, it refuses to rotate to UIInterfaceOrientationPortraitUpsideDown. Why?
Okay, once we get that figured out, there is a follow up question... I have a single view controller within my app that I only want to support UIInterfaceOrientationPortrait and UIInterfaceOrientationPortraitUpsideDown how can I achieve this? I have the following code in my controller and it doesn't do the trick:
// The following method never gets called (but wanted to
// include this to show that I've tried it).
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
// This method does get called but has no effect. The VC that this method
// belongs to rotates to all interface orientations except for
// UIInterfaceOrientationPortraitUpsideDown which is definitely
// not what I want...
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}
// This method never gets called either and therefore has no effect...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
Note that my app is storyboard based (if that makes any difference). Any help would be much appreciated! Thanks.
By doing what is explained in Landscape Mode ONLY for iPhone or iPad and adding evey interface orientation when doing it, it will support all orientations.
Change your App's Info.plist file:
Add Supported interface orientations row to your App's Info.plist file with all the supported interface orientation's
Add the supported interface orientation's to "Supported Interface Orientations".
(Targets -> YourApp -> Supported Interface Orientations -> Landscape Left & Right)

How to rotate the ipad screen using code in my ios app

When my app is launched, it is initially in portrait orientation. It can rotate when the ipad device is physically rotated.
I hope to add a function that allows users to click a button to open a help tutorial. I want the tutorial to only be landscape.
So I override the shouldAutorotateToInterfaceOrientation method to check if the app is in help tutorial mode; returning 'Yes' if it is:
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation ==UIInterfaceOrientationLandscapeRight)`
When the screen is in portrait, and the user clicks the button to open the help tutorial, how do I rotate the screen to landscape at the beginning of my button response code?
If the controller with the help tutorial doesn't support Portrait, it will automatically show the image in Landscape mode, even if the user doesn't hold the device like that, you shouldn't need to "rotate" the screen yourself, through code.
If you want to rotate your view manually (but NOT change the device orientation), use this code for a 90 degrees rotation
CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI_2);
self.view.transform = transform;
M_PI_2 = 90 degrees
M_PI = 180 degrees

How to force UIInterfaceOrientation?

I am writing an app and run into two problems. I have been searching the web all night without success and wonder if anyone here can help.
When the application starts, I want it to default to Landscape mode and Detect whether it is in UIInterfaceOrientationLandscapeLeft or UIInterfaceOrientationLandscapeRight. I have created the UI in landscape mode in the .xib file. However, when I check self.interfaceOrientation it always returns UIInterfaceOrientationLandscapeLeft regardless of whether the home button is on the left or right in the iPad simulator.
When the user rotates the iPad between the two landscape orientation, I want the view the change. To illustrate with a simplified example, if it is UIInterfaceOrientationLandscapeLeft, I want to write 1 on the left side of the screen and 2 on the right side of the screen. In UIInterfaceOrientationLandscapeRight, write 2 on the left side of the screen and 1 on the right side of the screen. Which method in iOS can tell me whenever the user rotates the device?
Thanks very much in advance.
Joe
Where are you checking that? If you're doing it in applicationDidFinishLaunching or in the view controller's viewDidLoad then it's likely the interface orientation isn't set properly yet. Wait until viewWillAppear or viewDidAppear to check that.
Take a look at shouldAutorotateToInterfaceOrientation in your view controller. You need to return YES to supported orientations so in your case you want to return YES if interfaceOrientation is landscape (there's a helper function for checking landscape vs portrait by the way). Also look at didRotateFromInterfaceOrientation which tells you when the user has rotated.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

Resources