Reporting incorrect bounds in landscape Mode

前端 未结 9 1137
青春惊慌失措
青春惊慌失措 2020-12-05 02:57

I am having an issue with Landscape mode in my iPad application.

I created a very small new project to show my issue I set UIInterfaceOrientation in the pList to UII

9条回答
  •  猫巷女王i
    2020-12-05 03:22

    I had the same thing happen to me.

    You have to spoon-feed iOS and put this line of code here or else it will give you the wrong answer.

    -(void) viewWillAppear:(BOOL)animated
    {
      [super viewWillAppear:animated];
      //required because device orientation will give you the wrong values
      [UIViewController attemptRotationToDeviceOrientation];
      int orientation = [[UIDevice currentDevice] orientation];
      BOOL isPortrait = false;
    
      if (orientation == 3 || orientation == 4)
        isPortrait = false;
      else
        isPortrait = true;
      NSLog(@"is portrait %i ?", isPortrait);
    }
    

提交回复
热议问题