In Chapter 7, in the project ScreenRotations, the positionViews: method should have an additional parameter and the first line commented out:
Code:
-(void) positionViews:(UIInterfaceOrientation) destOrientation {
// UIInterfaceOrientation destOrientation = self.interfaceOrientation;
if (destOrientation == UIInterfaceOrientationPortrait ||
destOrientation == UIInterfaceOrientationPortraitUpsideDown) {
//â-if rotating to portrait modeâ-
btn.frame = CGRectMake(20, 20, 233, 37);
} else {
//â-if rotating to landscape modeâ-
btn.frame = CGRectMake(227, 243, 233, 37);
}
}
So, when calling the positionViews: method, you should call it with the destination orientation:
Code:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
[self positionViews:toInterfaceOrientation];
}
Finally, in the viewDidLoad method, call the positionViews: method with the current destination:
Code:
- (void)viewDidLoad
{
[self positionViews:[[UIApplication sharedApplication] statusBarOrientation]];
[super viewDidLoad];
}
The original code in the book works when using the positionView method with the willAnimateSecondHalfOfRotationFromInterfaceOrient ation: method. However, since the latter method is deprecated, you need to manually pass in the destination orientation to the positionViews method.