6

On my iPhone app I have it restricted to portrait only under the project targets deployment info

There is one page that I want only in landscape and I use the supportedInterfaceOrientations method to obtain that.

Standard implementation:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.Landscape
    }

It works perfectly on all iPhone devices and iOS version except for iPhone 6+. The supportedInterfaceOrientations method is never called.

I cant find any reason why this might be affecting just the iPhone 6+, any tips would be greatly apreciated.

JLoewy
  • 535
  • 1
  • 4
  • 17
  • I just created an empty single view application and verified that `supportedInterfaceOrientations()` was called for both 6 and 6 Plus. Can't immediately see how your code would be different unless the view controller is a child view controller to something else like a navigation vc, split vc, tab bar vc, etc. In which case make sure the parent view controller also responds as you would like. Only thing different with 6 Plus off of the top of my head is it's ability to use a split view in landscape. Maybe something there? – Scott H Oct 05 '15 at 23:21
  • The most likely reason is the size class for the iPhone 6+ will be regular width but compact width for all other iphones when presented in landscaoe. What kind of controller is it: a normal view controller or a container. If it is presented modally, I believe you need to use `preferredInterfaceOrientationForPresentation` – Rory McKinnel Oct 06 '15 at 12:13
  • According to the docs, `supportedInterfaceOrientations` will only be called on the root view controller, or on controllers which are presented to take up the entire screen. So chances are the controller you are implementing this in on iPhone 6+ does not meet the criteria. What kind of controller is it? Seems you should generally implement `supportedInterfaceOrientations` in the main container controllers like UINavigationController, UITabBarController and UISplitViewController. – Rory McKinnel Oct 09 '15 at 13:31

2 Answers2

3

you can try this code it works for me

// you have to import foundation
import Foundation

class YourViewController : UIViewController {
    var device = self.platform()

     override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(true)

     if device.lowercaseString.rangeOfString("iphone6plus") != nil {
     supportedInterfaceOrientations()
    }

    }

    // add this method to your view controller
    func platform() -> String {
            var sysinfo = utsname()
            uname(&sysinfo) // ignore return value
            return NSString(bytes: &sysinfo.machine, length: Int(_SYS_NAMELEN), encoding:
                NSASCIIStringEncoding)! as String
        }

Please note that this will not run on the simulator but will run perfectly on the actual device.

OverD
  • 2,612
  • 2
  • 14
  • 29
-1

Looking at this question, try this code snippet:

- (NSUInteger) supportedInterfaceOrientations
{
  if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
  {
    // iPhone 5S and below: 320x480
    // iPhone 6: 375x667
    // iPhone 6 Plus: 414x736
    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    // The way how UIScreen reports its bounds has changed in iOS 8.
    // Using MIN() and MAX() makes this code work for all iOS versions.
    CGFloat smallerDimension = MIN(screenSize.width, screenSize.height);
    CGFloat largerDimension = MAX(screenSize.width, screenSize.height);
    if (smallerDimension >= 400 && largerDimension >= 700)
      return UIInterfaceOrientationMask.Landscape;
    else
      return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
  }
  else
  {
    // Don't need to examine screen dimensions on iPad
    return UIInterfaceOrientationMask.Landscape;
  }
}

-Herzbube

Lacking an official Apple API, this is the workaround that I've come up with:

[Code]

The snippet simply assumes that a screen with dimensions above a semi-arbitrarily chosen size is suitable for rotation. Semi-arbitrarily, because a threshold of 400x700 includes the iPhone 6 Plus, but excludes the iPhone 6.

Although this solution is rather simple, I like it exactly because of its lack of sophistication. I don't really need to distinguish exactly between devices, so any clever solutions such as the one in Jef's answer are overkill for my purposes.

All I did was change the 1st and 3rd return values from UIInterfaceOrientationMaskAll to UIInterfaceOrientationMask.Landscape.

Community
  • 1
  • 1
Caleb Kleveter
  • 11,170
  • 8
  • 62
  • 92
  • 1
    I'm sorry but maybe I didn't explain the question clear enough. I know how to implement landscape for specific device. The problem is that supportedInterfaceOrientations doesn't get called on iPhone 6+ devices. That is 100% the problem and it only doesn't get called on iPhone 6+ devices. – JLoewy Oct 08 '15 at 00:11
  • @JLoewy, you are testing no an actual device? – Caleb Kleveter Oct 08 '15 at 01:43