可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
i added the new methods to my code like described at apples iOS 6 Documentations but on the iPhone 5 the App doesn't rotate to upside down. Only the to landscape Ways.
Here my Code from the rootViewController:
- (NSUInteger)supportedInterfaceOrientations{
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}
- (BOOL)shouldAutorotate{
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
return YES;
}
i tryed also "UIInterfaceOrientationMaskAll" but no changes. The Strange is, my iPhone 4 with iOS6 does totate o upside down with the same code.
Any Ideas?
回答1:
IOS 6 uses default Orientation UIInterfaceOrientationMaskAll
for iPad and UIInterfaceOrientationMaskAllButUpsideDown
for iPhone. If you want your ViewControllers on the iPhone to rotate to ALL orientations including UpsideDown you must add the iOS 6 method:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
to all view controllers. If you've done this and it is not working then I am betting your using a TabViewController or NavigationController where some of the views are NOT returning this. All ViewControllers must return this for ANY of them to support it.
Alternatively you can add a Category to the UITabViewController or NavigationController class that is your rootViewController and override that method. You do that like so:
@interface UITabBarController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations;
@end
@implementation UITabBarController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
@end
Also these are the currently recommended approaches now being discussed in Apple Developer Forums with Apple staff saying earlier documentation that discouraged sub classing of UINavigationController is out of date, and as of iOS 6 it is ok to do that.
回答2:
Thanks to Cliff Ribaudo really help full your answer for UITabbarController based project but in my case i am only using UINavigationController so i have modified your answer for UINavigationController categeory.
@interface UINavigationController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations;
@end
@implementation UINavigationController (RotationAll)
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
@end
回答3:
Forgive the verbosity, but I think your answer is below.
I was having the same problem, but it was occurring on all IOS 6 devices including my iphone 4. Reading your question actually answered mine. I had removed this ages ago because it wasn't doing anything:
- (NSUInteger)supportedInterfaceOrientations{
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown); }
and my code was working perfectly in prior ios releases. It appears this has become manditory in ios 6. But only for upsideDown. The other orientations were working fine.
So, thank you.
Back to your problem. Have you reviewed your project target to see if all "Supported Interface Orientations" are dark gray? I'm wondering if upside down is light gray, (ie, unchecked). I found in a quick test that on prior ios releases these are ignored too. As long as you return YES from shouldAutorotateToInterfaceOrientation it will support the orientations, but not in iOS 6.
Lastly, you have implemented shouldAutorotate, which I have not in my code. I think this defaults to Yes. And I think this just tells the os to try to rotate, but then you have to tell it which orientations you support with shouldAutorotateToInterfaceOrientation. But your snippet doesn't show that you've implemented shouldAutorotateToInterfaceOrientation. I would suggest implementing this as it tells the OS which orientations you support returning a simple YES means you support all.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return YES;
}
Hope this helps.
回答4:
Default target settings is no upside-down orientation, so try this:
Go to Project file
select your app target
select "Summery" tab
check that all orientation types pressed
Good luck :)
回答5:
If you plan to enable or disable rotation for all view controllers you don't need to subclass UINavigationController.
Instead use:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
in your AppDelegate.
If you plan to support all orientations in your app but different orientations on PARENT View Controllers (UINavigationController stack for example) you should use
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
from AppDelegate in combination with the following methods in your PARENT View Controller.
- (BOOL)shouldAutorotate
and
- (NSUInteger)supportedInterfaceOrientations
But if you plan to have different orientation settings in different CHILDREN ViewControllers in the same navigation stack (like me) you need to check the current ViewController in the navigation stack.
I've created the following in my UINavigationController subclass:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
int interfaceOrientation = 0;
if (self.viewControllers.count > 0)
{
id viewController;
DLog(@"%@", self.viewControllers);
for (viewController in self.viewControllers)
{
if ([viewController isKindOfClass:([InitialUseViewController class])])
{
interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
else if ([viewController isKindOfClass:([MainViewController class])])
{
interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
else
{
interfaceOrientation = UIInterfaceOrientationMaskAllButUpsideDown;
}
}
}
return interfaceOrientation;
}
Since you cannot control anymore from children ViewControllers the rotation settings of presented view controller you must somehow intercept what view controller is currently in the navigation stack. So that's what I did :). Hope that helps !