问题
I have made an app targeted for iOS 5 and iOS 6, and for some reason it only rotates when using it on devices with iOS 6, wether on an iPhone or an iPad, and doesn't rotate on devices using iOS 5. My app is universal. Please help me resolve this problem! Thanks
回答1:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
overide these two methods in your all uiviewcontroller subclasses ...... this will work for ios 6 and earlier
回答2:
iOS 5 and iOS 6 call different orientation and rotation delegates. In iOS 5, implement:
shouldAutorotateToInterfaceOrientation:, which is deprecated in iOS 6.
So, in iOS 6, make sure you set a root view controller, and implement:
shouldAutorotate:, supportedInterfaceOrientations and supportedInterfaceOrientationsForWindow:
回答3:
I had a similar issue. You can check the answer of this question:
Rotation behaving differently on iOS6
To summarize, to have autorotation fully work in iOS 5 and iOS 6, and also handling PortraitUpsideDown orientation, I had to implement a custom UINavigationController and assign it to self.window.rootViewController
in the app delegate didFinishLaunchingWithOptions
method.
回答4:
shouldAutorotateToInterfaceOrientation is deprecated in ios6.
so if you wnat to run app on both os version then add shouldAutorotateToInterfaceOrientation too as follows
//for ios6
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIInterfaceOrientationLandscapeLeft ||orientation == UIInterfaceOrientationLandscapeRight )
{
return YES;
}
return NO;
}
//for ios5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//interfaceOrientation == UIInterfaceOrientationLandscapeRight;
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||interfaceOrientation == UIInterfaceOrientationLandscapeRight ) {
return YES;
}
return NO;
}
回答5:
to support autorotations in both ios5 and ios6 we need to provide call backs in case of ios6....`[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
and we need to call
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutoRotate{
return YES;
}
for ios5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{ return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)); }
来源:https://stackoverflow.com/questions/13100347/app-only-rotates-in-ios-6-and-not-in-ios-5