How do I code for the landscape orientation in iPhone?

拜拜、爱过 提交于 2019-12-25 02:48:06

问题


I understand that I can change what interface orientations are supported, but if I want the landscape view to be entirely different, or somewhat different than the portrait view, how do I code for it?

Thank you.


回答1:


Just load another view controller when the orientation changes. To make things simple, I often use a hidden navigation controller and push and pop the views I want for any particular orientation.




回答2:


Using a dedicated view controller for each orientation is the easiest approach.

If the only difference is presentation, not controller logic, then you could also try coding a single view controller to swap between two views depending on orientation.

E.g. pseudocode

UIView *landscapeView = ...;
UIView *portraitView = ...;

when orientationChanged
{
   if landscape then 
      [portraitView setHidden:YES];
      [landscapeView setHidden:NO];
      self.view = landscapeView;
   else if portrait then
      [landscapeView setHidden:NO];
      [portraitView setHidden:YES];
      self.view = portraitView;


   [self.view setNeedsDisplay];
}


来源:https://stackoverflow.com/questions/3420039/how-do-i-code-for-the-landscape-orientation-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!