Oct 27

IOS reminds me of IE

Developing for IOS is exactly like developing for IE.

First, you knock the easy stuff out that *just works* simply without massive confusion. In browser land that means do your work in chrome or firefox first, whereas in IOS you basically do everything except auto-rotation first.

Then, for the last step, you spend as much time handling IE bugs or IOS auto rotation hell as you spent developing up to that point.


The trick in IOS 6+ seems to be something like this inside your view controller..

  1. (NSUInteger)supportedInterfaceOrientations {
  2.     return UIInterfaceOrientationMaskAll;
  3. }
  5. (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  6.     CGRect screenRect = [[UIScreen mainScreen] bounds];        
  7.     screenRect = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height); //anchor to 0,0
  8.     if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
  9.         //swap width & height
  10.         screenRect = CGRectMake(0, 0, screenRect.size.height, screenRect.size.width);
  11.     }
  12.     self.view.frame = screenRect;
  13.     self.view.bounds = screenRect;
  14. }

Don’t bother with trying to detect orientation during viewWillLayoutSubviews, you need to have saved the information of the upcoming orientation off by then, apparently..