我有一个应用程序的问题。我无法锁定我的应用程序的方向。我需要做的就是将一个视图控制器锁定为横向模式,其他的则为纵向。
这是我的应用程序的层次结构。
*Navigation Controller
*TabBarController
*ViewControllers
我有一个应用程序的问题。我无法锁定我的应用程序的方向。我需要做的就是将一个视图控制器锁定为横向模式,其他的则为纵向。
这是我的应用程序的层次结构。
*Navigation Controller
*TabBarController
*ViewControllers
你只需要在shouldAutorotate
方法中返回NO
,并在supportedInterfaceOrientation
方法中返回横向的方向,以使其处于横屏状态。
另外,在shouldAutorotate
方法中也要返回NO
,并从supportedInterfaceOrientation
方法中返回纵向的方向掩码。
在所有的视图控制器中:
-(BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft;
}
在控制器中,您希望以纵向显示:
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
使用以下两种方法将设备方向锁定为横屏。
- (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;
}
使用 NavigationController
-(BOOL)shouldAutorotate
-(NSUInteger)supportedInterfaceOrientations
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
如果您使用“show segue(push)”方法,则永远不会调用这些方法。
请改用“showDetail”方法而非“show”方法。