UIInterfaceOrientation Problemer
UIViewController A , B.
A implements Horizontal screen , A turn to B. how do what? cancel Horizontal screen for B.
B code :
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orie开发者_如何学Pythonntations
return NO;
}
Is not ok! Why?? Please help me ! thanks!
If B is on a tab bar with A this will not work. You need to present B modally or push it onto a nav controller - and you also need to return YES for at least one orientation in B.
Tab bar controllers only support the orientations that are supported by ALL of their views.
I just fixed this in my app under iOS 5.1. This is an old question, but I'm leaving this here for posterity since I haven't seen anyone else solve this without applying gobs of CGAffineTransform code and not fixing the real problem, which is that the UIInterfaceOrientation and the UIDeviceOrientation are out of sync.
In my case, I only needed to fix the orientation when I was coming from a portrait-only ViewController and into a Portrait-and-Landscape ViewController when the device had been physically rotated prior to the transition.
// The "Interface Orientation" and the "Device Orientation" can become separated in some cases.
// Make sure the view controller only supports the interface orientation for the current device rotation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
int deviceRotation = [[UIDevice currentDevice] orientation];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
if (deviceRotation == UIDeviceOrientationUnknown ||
deviceRotation == UIDeviceOrientationFaceUp ||
deviceRotation == UIDeviceOrientationFaceDown)
return YES;
if (deviceRotation != interfaceOrientation)
return NO;
else
return YES;
}
精彩评论