开发者

How do I code for the landscape orientation in iPhone?

I understand that I can change what interface orientations are supported, but if I want the landscape view to be enti开发者_开发问答rely different, or somewhat different than the portrait view, how do I code for it?

Thank you.


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.


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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜