Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Moving Views

If autosizing provides a practically no-work solution to orientation changes, moving views offers a fix with higher-bookkeeping responsibilities. The idea works like this: After a view controller finishes its orientation, it calls the delegate method didRotateFromInterfaceOrientation:. Listing 4-4 implements a method that manually moves each view into place. As you can see, this approach quickly gets tedious, especially when you are dealing with more than four subviews at a time.

Listing 4-4. Positioning Views in Code

- (void)didRotateFromInterfaceOrientation:
    (UIInterfaceOrientation) fromInterfaceOrientation
{
  // Move the Fahrenheit and Celsius labels and fields into place
  switch ([UIDevice currentDevice].orientation)
  {
      case UIInterfaceOrientationLandscapeLeft:
      case UIInterfaceOrientationLandscapeRight:
      {
          flabel.center = CGPointMake(61,114);
          clabel.center = CGPointMake(321, 114);
          ffield.center = CGPointMake(184, 116);
          cfield.center = CGPointMake(418, 116);
          break;
      }
      case UIInterfaceOrientationPortrait:
      case UIInterfaceOrientationPortraitUpsideDown:
      {
          flabel.center = CGPointMake(113, 121);
          clabel.center = CGPointMake(139, 160);
          ffield.center = CGPointMake(236, 123);
          cfield.center = CGPointMake(236, 162);
          break;
      }
      default:
          break;
   }
}

					  


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint