Reputation: 1842
I have the following view hierarchy
In fact there is a Root ScrollView Controller which has multiple Sub ScrollViews. (the Root ScrollViewController only scrolls horizontal - the sub ones only vertical). Each Sub ScrollView has an UIViewController.
My Root ScrollView Controller works as expected and calls my rotation methods which look like the following:
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self rotateScrollViewToInterfaceOrientation:toInterfaceOrientation];
}
- (void) rotateScrollViewToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
// do some rotation logic
}
}
I have used the same methods in my Sub ScrollViews and UIViewControllers but they don't get called on rotation.
Anyone has an idea why?
Upvotes: 0
Views: 2510
Reputation: 1412
The shouldAutorotateToInterfaceOrientation method is deprecated and will no longer be called as of iOS 6.
try to implements these following methods.
-(BOOL)shouldAutomaticallyForwardAppearanceMethods{
// This method is called to determine whether to
// automatically forward appearance-related containment
// callbacks to child view controllers.
return YES;
}
-(BOOL)shouldAutomaticallyForwardRotationMethods{
// This method is called to determine whether to
// automatically forward rotation-related containment
// callbacks to child view controllers.
return YES;
}
note : these methods just supported in iOS 6.
Upvotes: 2
Reputation: 5520
From iOS 6.0 release notes:
Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method of UIViewController is deprecated. In its place, you should use the supportedInterfaceOrientationsForWindow: and shouldAutorotate methods. More responsibility is moving to the app and the app delegate. Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate. By default, an app and a view controller’s supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom. A view controller’s supported interface orientations can change over time—even an app’s supported interface orientations can change over time. The system asks the top-most full-screen view controller (typically the root view controller) for its supported interface orientations whenever the device rotates or whenever a view controller is presented with the full-screen modal presentation style. Moreover, the supported orientations are retrieved only if this view controller returns YES from its shouldAutorotate method. The system intersects the view controller’s supported orientations with the app’s supported orientations (as determined by the Info.plist file or the app delegate’s application:supportedInterfaceOrientationsForWindow: method) to determine whether to rotate. The system determines whether an orientation is supported by intersecting the value returned by the app’s supportedInterfaceOrientationsForWindow: method with the value returned by the supportedInterfaceOrientations method of the top-most full-screen controller. The setStatusBarOrientation:animated: method is not deprecated outright. It now works only if the supportedInterfaceOrientations method of the top-most full-screen view controller returns 0. This makes the caller responsible for ensuring that the status bar orientation is consistent. For compatibility, view controllers that still implement the shouldAutorotateToInterfaceOrientation: method do not get the new autorotation behaviors. (In other words, they do not fall back to using the app, app delegate, or Info.plist file to determine the supported orientations.) Instead, the shouldAutorotateToInterfaceOrientation: method is used to synthesize the information that would be returned by the supportedInterfaceOrientations method.
Upvotes: 1