我目前在iOS 5上遇到屏幕旋转问题。在iOS 6上,一切正常,但旋转不适用于iOS 5即使通知UIDeviceOrientationDidChangeNotification
被调用。屏幕旋转不适用于iOS 5但适用于iOS 6
我使用Storyboard
这是我的ViewController
是怎么样的:
为了旋转我使用下列方法屏幕:
CustomTabBarViewController.mm(UITabBarController
)
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
if (isLandscapeOK) {
// for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
return UIInterfaceOrientationMaskAllButUpsideDown;
}
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (isLandscapeOK) {
// for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown);
}
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
TabBarItemController.mm(UINavigationView
)
-(BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
LoyaltyListController.mm(UIViewController
)
- (void) didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
{
self.navigationController.navigationBarHidden = YES;
[self hideTabBar:self.tabBarController];
portraitView.hidden = YES;
landscapeView.hidden = NO;
}
else if (orientation == UIDeviceOrientationPortrait)
{
self.navigationController.navigationBarHidden = NO;
[self showTabBar:self.tabBarController];
portraitView.hidden = NO;
landscapeView.hidden = YES;
[notificationView setFrame:CGRectMake(0, - (notificationView.frame.size.height + 40), notificationView.frame.size.width, notificationView.frame.size.height)];
}
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
[(CustomTabBarViewController*)[self tabBarController] setLandscapeOK:YES];
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown);
}
这里是iOS 5的屏幕:
肖像:
景观:(没旋转)
下面是它应该是什么样子:
任何想法?
你检查我的源代码???这就是我正在使用的... ' - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return(interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown); }' – Jeremy
哦,我完全错过了它。再检查一遍!不要使用UIInterfaceOrientationMaskAllButUpsideDown。 您只需根据interfaceOrientaion的值返回YES或NO。 你将不得不使用||看看你想支持哪一个。 在这种情况下,因为你想支持所有除了颠倒,我已经写了代码的方式。 –
没错,没有看到'UIInterfaceOrientationMaskAllButUpsideDown'是iOS6及更高版本:)我现在会测试它 – Jeremy