Get launch orientation of iPad app

后端 未结 9 720
无人及你
无人及你 2020-12-02 16:19

In my iPad app, I need to run some layout code to set the proper layout depending on the orientation. By default, the layout is configured for the landscape orientation, so

9条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 16:45

    As mentioned in a blog post above, there is a set of macros for testing orientation. That blog post however mentions UIDeviceOrientationIsPortrait. I like the following below, it's a minor twist.

    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
    {
      NSLog(@"Portrait");
    }
    else
    {
      NSLog(@"Landscape");
    }
    

    An observation I've made is that you can't call this code in a table view, pushed on to a Navigation Controller embedded in the split view controller. So in other words you can't call it from the master view controller. You have to replace the "self.interfaceOrientation" with splitviewcontroller.interfaceOrientation, assuming you maintain a reference to the parent split view controller.

提交回复
热议问题