iOS 单独设置某个控制器横屏 —— HERO博客

来源:互联网 发布:mysql中full join报错 编辑:程序博客网 时间:2024/05/29 05:56

iOS程序开发中,若要单独让某个控制器横屏,可以用如下方法:

  • 在 AppDelegate.h 添加属性:

//屏幕方向@property (nonatomic, assign) NSInteger allowRotation;

  • 在 AppDelegate.m 添加方法:

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{    if (_allowRotation == 1) {        return UIInterfaceOrientationMaskLandscapeRight;            }else {        return UIInterfaceOrientationMaskPortrait;    }}

  • 可以在跳转控制器中设置:

HWGoalVC *vc = [[HWGoalVC alloc] init];[self.navigationController presentViewController:vc animated:YES completion:nil];

  • 在目标控制器中设置:

AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;appDelegate.allowRotation = 1;
  • 在目标控制器返回时设置:

- (void)back{    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;    appDelegate.allowRotation = 0;    [self dismissViewControllerAnimated:YES completion:nil];}
  • 若想隐藏StatusBar,可调用如下方法:

- (BOOL)prefersStatusBarHidden{    //iOS7前隐藏StatusBar    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];    //iOS7以后隐藏StatusBar    return YES;}


4 0
原创粉丝点击