Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UINavigationController中带有UITabbar的方向锁定_Ios_Objective C_Iphone_Uiviewcontroller_Uiinterfaceorientation - Fatal编程技术网

Ios UINavigationController中带有UITabbar的方向锁定

Ios UINavigationController中带有UITabbar的方向锁定,ios,objective-c,iphone,uiviewcontroller,uiinterfaceorientation,Ios,Objective C,Iphone,Uiviewcontroller,Uiinterfaceorientation,我想在几个UIViewcontroller中锁定方向 1) Loginview(仅支持纵向)具有登录按钮的UIViewcontroller 2) 在登录按钮上,我从情节提要调用UITabbarController,有3个选项卡,所有选项卡都嵌入UINavigationControllers。(表1、表2、表3) 3) 在具有按钮1的选项卡1(支持横向和纵向)上,我从中按下UIViewcontroller演示(仅支持纵向)。如下 Demo *vc = [self.storyboard insta

我想在几个UIViewcontroller中锁定方向

1) Loginview(仅支持纵向)具有登录按钮的UIViewcontroller

2) 在登录按钮上,我从情节提要调用UITabbarController,有3个选项卡,所有选项卡都嵌入UINavigationControllers。(表1、表2、表3)

3) 在具有按钮1的选项卡1(支持横向和纵向)上,我从中按下UIViewcontroller演示(仅支持纵向)。如下

 Demo *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Demo"];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
演示已成功加载,但我想将其旋转锁定为纵向,因此我创建了一个UINavigationController类别,但它仍在旋转

#import <UIKit/UIKit.h>

@interface UINavigationController (Orientation)

@end
//-------在我的演示uiviewcontroller中,我看到了下面的代码,但它从未调用--------


我读了很多帖子,但没有一篇是有帮助的,请帮助我了解如何做?

初始设置方向为纵向仅在目标->常规->部署信息中(见下图)

在AppDelegate.h中声明属性:

@property (assign, nonatomic) BOOL shouldRotate;
在AppDelegate.m中定义

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if (self.shouldRotate)
        return UIInterfaceOrientationMaskAllButUpsideDown;
    else
        return UIInterfaceOrientationMaskPortrait;
}
在UIViewController实现中设置应旋转值,如下所示:

如果要旋转,请设置“是”

-(void) viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        [(AppDelegate *)[[UIApplication sharedApplication] delegate] setShouldRotate:YES];
    }
否则就不行了

-(void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] setShouldRotate:NO];
}
注意:设置应旋转:始终调用视图显示:。因此,无论何时切换UIViewController,它都会正常工作


希望这对你有用。最好的:)

仅在目标->常规->部署信息中初始设置方向为纵向(见下图)

在AppDelegate.h中声明属性:

@property (assign, nonatomic) BOOL shouldRotate;
在AppDelegate.m中定义

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if (self.shouldRotate)
        return UIInterfaceOrientationMaskAllButUpsideDown;
    else
        return UIInterfaceOrientationMaskPortrait;
}
在UIViewController实现中设置应旋转值,如下所示:

如果要旋转,请设置“是”

-(void) viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        [(AppDelegate *)[[UIApplication sharedApplication] delegate] setShouldRotate:YES];
    }
否则就不行了

-(void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] setShouldRotate:NO];
}
注意:设置应旋转:始终调用视图显示:。因此,无论何时切换UIViewController,它都会正常工作


希望这对你有用。祝您一切顺利:)

感谢yeshica…提供帮助…但如果用户处于横向模式,则跳转视图也会显示在横向模式中。@iphonemaclover:
setShouldRotate
值为该ViewController的“ViewDidAppease”方法中的
NO
。@iphonemaclover:如果您觉得此代码有帮助,请不要只感谢mark也接受了。已经投票赞成它@Yashica…但接受的答案应该处于工作状态…因此它将解决我的问题并帮助其他用户…感谢yeshica…提供帮助…但如果用户处于横向模式,则跳转视图也会显示在横向模式中…@iphonemaclover:
setShouldRotate
值为该视图控制器中的
NO
方法。@iphonemaclover:如果您觉得这段代码很有用,请不要只感谢mark Accepted。已经投票给@Yashica…但接受的答案应该处于工作状态…这样可以解决我的问题,也可以帮助其他用户。。。