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

How to change interface orientation from landscape to portrait when back button is tapped in Objective C

我的这个项目需要横向才能查看图表,点击后退按钮后,它应该 return 到纵向才能查看菜单 Daily GraphCarcadian Graph。当用户点击 Daily Graph 它以横向显示图形时,趋势用户将在横向视图中按住他的 phone 并且当 back 按钮被点击到 return 到菜单纵向运行流畅,但是当用户点击 Carcadian Graph 时它显示横向图形,趋势,用户将在横向视图中按住他的 phone 并且当 back 按钮被点击到 return 在 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;
   }
}

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