我的應用程序出現問題。我無法鎖定我的應用程序的方向。我需要做的只是將一個視圖控制器鎖定到橫向模式,其餘都是縱向模式。如何在iOS 7和iOS 8中鎖定設備方向
這是我的應用程序的層次結構。
*Navigation Controller
*TabBarController
*ViewControllers
我的應用程序出現問題。我無法鎖定我的應用程序的方向。我需要做的只是將一個視圖控制器鎖定到橫向模式,其餘都是縱向模式。如何在iOS 7和iOS 8中鎖定設備方向
這是我的應用程序的層次結構。
*Navigation Controller
*TabBarController
*ViewControllers
你只需要從supportedInterfaceOrientation
你想在景觀一個返回從shouldAutorotate
NO
和橫向方向。
另一方面,也從shouldAutorotate
返回NO
方法和肖像方向掩碼從supportedInterfaceOrientation
。
在所有viewControllers:
-(BOOL)shouldAutorotate {
return NO;
}
在一個要進行橫向:
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft;
}
在控制器要在肖像:下面
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
請注意,iOS 7和8使用不同的方法來確定UI方向 – Raptor
是的,但這些方法適用於兩個操作系統。 –
我試圖此代碼 - (NSUInteger)應用:(UIApplication的*)應用supportedInterfaceOrientationsForWindow:(一個UIWindow *)窗口{ 返回UIInterfaceOrientationMaskPortrait; } 它的工作原理,但我如何只看到一個視圖控制器? – user3205472
使用2這種方法將設備方向鎖定到橫向。
- (NSUInteger)supportedInterfaceOrientations{
[super supportedInterfaceOrientations];
return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
{
return YES;
}
// Return YES for supported orientations
return NO;
}
它的工作原理,但我的問題是,我的看法仍然在旋轉如何鎖定在某個視圖中的方向和休息是肖像。謝謝。 – user3205472
隨着NavigationController
-(BOOL)shouldAutorotate
-(NSUInteger)supportedInterfaceOrientations
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
這些方法從來沒有所謂的,如果你用 '秀賽格瑞(推送)'。
變化賽格瑞 'showDetail',而不是 '秀'
嗨!感謝您的迴應,但我並未在此項目中使用故事板。我怎樣才能做到這一點? – user3205472
哪裏是你的代碼? – Raptor
這是我使用的代碼 - (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations返回UIInterfaceOrientationMaskLandscape; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation返回UIInterfaceOrientationLandscapeLeft; } – user3205472
您可以編輯您的問題以發佈代碼。 – Raptor