0

I have an iPhone only app. But there are use cases where app is run on iPad. For eg. apple tests it on iPad.

I am struggling with getting device rotation right for iPad. Its very different from iPhone.

The idiom solution will not works as it returns iPhone even for iPad

So I wanted to at least force portrait only for iPad devices.

So I did following:

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{

    if ([[UIDevice currentDevice].model rangeOfString:@"Pad"].location != NSNotFound) {

        return UIInterfaceOrientationMaskPortrait; /* Device is iPad */
    }
    return UIInterfaceOrientationMaskAll;
}

Can use the above solution reliably?

GJain
  • 5,025
  • 6
  • 48
  • 82
  • 1
    Have you set your project type to "iPhone" or "universal"? If your project is iPhone only then you shouldn't need to do anything special on an iPad – Paulw11 Jul 12 '16 at 22:25
  • Are you using autolayout? It is better to solve your layout problem than to write device specific code – Paulw11 Jul 12 '16 at 22:31
  • Probably because you are not using autolayout ;). Autolayout makes things like rotation much simpler. – Paulw11 Jul 12 '16 at 22:34
  • I have looked at your other two questions. With autolayout, the solution your first problem is one constraint that sets the bottom of the tableview to the vertical centre of the containing view, and then all of that code and special processing required by your 2nd and 3rd questions goes away – Paulw11 Jul 12 '16 at 22:46
  • Thanks you. I will use autoLayout asap. I used autoResizing and I know it helps removing and not writing lot of code. I will read up autoLayout asap. – GJain Jul 12 '16 at 22:49
  • Autoresizing was deprecated in favour of autolayout about 4-5 years ago. Autolayout is much more flexible. There is a learning curve, but it is worth it. My tips are don't overconstrain (add too many constraints), don't use "add missing constraints" or "reset to suggested constraints" - they almost never do what you want. The system needs to be able to determine a location and size for each item; think about what should be fixed on your screen, a label, a table, whatever and set its/their location(s) and size. Everything else should be located in relation to some other object – Paulw11 Jul 12 '16 at 22:53

0 Answers0