旋转屏幕wint导航控制器

时间:2014-05-06 14:52:00

标签: ios iphone rotation screen-rotation

我可以禁用所有屏幕的旋转,也不能禁用iPhone的旋转。 我怎么能这样做? 我使用初始portrate / landscape进行了很多组合,并遵循方法,但没有得到它。 如果我在应用设置中启用了横向,则所有屏幕都会旋转。我现在无法使用设备,我在模拟器上测试它。

 - (BOOL)shouldAutorotate
 {
return NO;
}

- (NSUInteger)supportedInterfaceOrientations
 {
//Choose your available orientation, you can also support more tipe using the symbol |
//e.g. return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight)
return (UIInterfaceOrientationMaskPortrait);
}

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,首先在构建设置>目标>部署信息的所有方向上选中复选标记。 然后在你的app委托文件中实现这个:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{

UIViewController *currentViewController = [self topViewController];

// Check whether it implements a dummy methods called canRotate
if ([currentViewController respondsToSelector:@selector(canRotate)]) {
    // Unlock landscape view orientations for this view controller
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

// Only allow portrait (standard behaviour)
return UIInterfaceOrientationMaskPortrait;

}

-(UIViewController*)topViewController {
return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];

}

- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController{     

if([rootViewController isKindOfClass:[UINavigationController class]]) {         UINavigationController * aNavigationController =(UINavigationController *)rootViewController;

    return [self topViewControllerWithRootViewController:aNavigationController.visibleViewController];

}
else
{
    return rootViewController;
}

}

在您的视图控制器中(假设为E)您想要成像/横向..

添加:

//run time flag method

- (void)canRotate //也在头文件中声明 {

}

- (BOOL)shouldAutorotate

{     返回YES; }

你已经完成了。

有关详情,请访问此link

答案 1 :(得分:0)

您需要继承UINavigationController并将ViewControllers嵌入导航控制器中。

@implementation CustomNavigationController
// -------------------------------------------------------------------------------
//  supportedInterfaceOrientations:
//  Overridden to return the supportedInterfaceOrientations of the view controller
//  at the top of the navigation stack.
//  By default, UIViewController (and thus, UINavigationController) always returns
//  UIInterfaceOrientationMaskAllButUpsideDown when the app is run on an iPhone.
// -------------------------------------------------------------------------------
- (NSUInteger)supportedInterfaceOrientations
{
    return [self.topViewController supportedInterfaceOrientations]; 
}
// -------------------------------------------------------------------------------
//  shouldAutorotate
//  Overridden to return the shouldAutorotate value of the view controller
//  at the top of the navigation stack.
//  By default, UIViewController (and thus, UINavigationController) always returns
//  YES when the app is run on an iPhone.
// -------------------------------------------------------------------------------
- (BOOL)shouldAutorotate
{
    return [self.topViewController shouldAutorotate];
}  

对于每个ViewController,您可以覆盖其shouldAutorotatesupportedInterfaceOrientations方法。