How to do orientations in iphone and ipad for ios6? - ios6.1

How to do orientations in iphone and ipad for ios 6? previous versions showing shouldrotateinterfaceorientation but latest version not showing ?
iam facing problems with orientations for latest version? plz help me?

Try this method. In iOS 6 we started using masks.
- (BOOL) shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
You can choose the rotations that you want from what I placed in here and remove the masks that you don't want. Good Luck.

Related

iOS 11 Device Orientation Autorotation

For iOS 10 and below, the following code controlled the orientation of the any respective UIViewController. I have selected Portrait, Landscape Left, and Landscape Right in my Deployment Info, and have the following in my Info.plist:
For my VC's that should not rotate at all I have the following code, which I stated, was working prior iOS 11
- (BOOL)shouldAutorotate {
[super shouldAutorotate];
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
[super supportedInterfaceOrientations];
return UIInterfaceOrientationMaskPortrait;
}
I have tested this on actual devices and as of iOS 11 it does not work.
Even more strangely, logging the registered device orientation as of iOS 11 tells my the device IS portrait... when the controller loads in landscape mode...
Code:
// In viewDidLoad
NSLog(#"orientation: %lu", [[UIDevice currentDevice] orientation]);
Console output:
2017-09-22 15:20:26.225196-0400 <APP_NAME>[2669:1628408] orientation: 1
This occurs either rotating the device left or right before building and running the app.
What is the cause here for this error? If anyone knows please help..
FYI: No, I do not have rotation lock on my device..
Whether this proves to be an iOS 11 bug or not, I seemed to have stumbled upon a "solution" to this issue. For whatever reason, for iOS 11 changing the - (BOOL)shouldAutorotate return to YES allows for the correct orientation...
Objc
- (BOOL)shouldAutorotate {
[super shouldAutorotate];
if (#available(iOS 11, *)) return YES;
return NO;
}
In combination I had to do a manual check for the screen dimensions to see if the width was greater or less than the supposed height of the screen.
width = self.view.frame.size.width, height = self.view.frame.size.height;
if (height < width) width = height, height = self.view.frame.size.width;
Hopefully someone else finds the true cause of this "bug" OR Apple updates their bundle to handle rotations like all previous iOS versions..
Swift 3.2+
override var shouldAutorotate: Bool {
if #available(iOS 11.0, *) {
// Anything else iOS 11 specific
return true
}
return false
}

Forcing Portrait Orientation if iOS

I've made a puzzle game ('WordBatch', available in the App store) and thought I had forced portrait orientation but its still rotating to landscape mode, though only the iPad. In XCode I specified it as a 'Universal' App, for all devices, and checked portrait mode only in the General tab. Even in the plist file portrait is the only orientation specified. I've tried all the suggestions in StackOverflow on this subject, but to no avail. The current code I have on place is this bit in my AppDelegate:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
and the following is in my root view controller:
-(BOOL)shouldAutorotate {
return NO;
}
but it still rotates to landscape. Any help here would be great.
You can try by applying this check:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// The device is an iPad.
}
else
{
// The device is an iPhone or iPod.
}

Locking orientation issue in iphone

I have a structure like this
LoginViewController-->Root
LoginViewController-->UINav---->HomeViewController
Now I have to lock this orientation to portrait only for iPhone and have to provide both orientations for iPad
For the Login Controller, I wrote this
-(BOOL)shouldAutorotate{
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
return YES;
}
else
{
return NO;
}
}
This is working fine. I got only a portrait orientation in iPhone and both portrait as well as landscape orientation in iPad
But the same piece of code is written in HomeViewController is not working.
Is it due to the Navigation Controller which is embedded with HomeViewConroller.
Well. I got a fix for that myself. Posting the solution on what to do as it might help others too.
Just uncheck the Device Orientation checks (LandscapeLeft and LandscapeRight) in Target->General
And write the same piece of code in every controller
-(BOOL)shouldAutorotate{
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
return YES;
}
else
{
return NO;
}
}
This worked for me. Now I only get a portrait mode in iPhone and a landscape as well as a portrait mode in iPad.

preferredContentSize not working in ios 7?

I am using modalPresentationStyle of type UIModalPresentationFormSheet to show my view.I want specific size of the view so using preferredContentSize which working in iOS 8 and showing exact how I wanted but same breaks for iOS 7 it's come as full sheet.View size changed.
Where as I wanted like below image
Any idea?
Please check below conditional code for iOS 8.x and iOS 7
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0"))
{
modalController.preferredContentSize = CGSizeMake(frameSize.x, frameSize.y);
}
else
{
modalController.view.superview.frame = CGRectMake((screenWidth - frameSize.x)/2, (screenHeight - frameSize.y)/2, frameSize.x, frameSize.y);
}
Hope this will help you.

Landscape for only certain devices in iOS 8.0

With iOS 8.0 in Xcode 6, there is nowhere where I can see that you can specify for each device if you want it portrait or landscape...
I want to have all iPhones only portrait except 6 Plus which should be both portrait and landscape. And I want all iPads to be both portrait and landscape.
Is there a way to do this or even a workaround it?
To make the 6+ different than other iPhones you'll need to implement supportedInterfaceOrientations something like this:
- (NSUInteger)supportedInterfaceOrientations
{
if (iPadOrPhonePlus()) {
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
I haven't settled on a way I like for that helper method but you can start with this:
.#define iPadOrPhonePlus() ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || [[UIScreen mainScreen] scale] > 2)
ignore the . before the #define SO was formatting it strangely without that.

Resources