我目前在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