Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
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.
|
Code View:
Scroll
/
Show All - (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;
}
}
|