首页 > 解决方案 > 在Objective C中点击后退按钮时如何将界面方向从横向更改为纵向

问题描述

我有这个项目需要横向查看图表,一旦点击后退按钮,它应该返回纵向查看菜单Daily GraphCarcadian Graph. 当用户点击Daily Graph它以横向显示图形时,趋势用户将手持手机以横向视图,当back点击按钮返回菜单时,纵向运行平稳,但当用户点击Carcadian Graph它以横向显示图形时,趋势,用户将在横向视图中握住他的手机,当back点击按钮返回时menuVC,它只会保持横向,它应该是纵向的。我该如何解决它,需要一些帮助,因为我是 Objective C 的新手。谢谢

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    if (self.orientation == UIInterfaceOrientationLandscapeRight)
    {
        UINavigationController *navController =(UINavigationController*)[self.tabBarController selectedViewController];
    UIViewController *dispViewController = navController.viewControllers.lastObject;

        if ([dispViewController.nibName isEqualToString:@"dailyGraph_vc"] == YES || [dispViewController.nibName isEqualToString:@"circadianGraph_vc"] == YES)
        {
           return 0;
        }
        else
          {
            return UIInterfaceOrientationMaskPortrait;
          }
       }
      else
    {
      return 0;
   }
}

标签: iosobjective-cscreen-orientation

解决方案


你可以[[UIDevice currentDevice] setValue:@(UIDeviceOrientationPortrait) forKey:@"orientation"];在上面viewWillDisappear或其他地方做。它支持 UIView 动画块


推荐阅读