iPad/iPhone multiple orientations best practice?

前端 未结 3 1255
孤街浪徒
孤街浪徒 2021-01-03 07:29

I\'d like to convert my views to work for any orientation (especially since it recommended for iPad). I\'ve been using IB to lay things out, and am not sure how to best pro

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-03 07:52

    You can make two separate views in the same XIB, and then implement the following code:

    To @interface

    IBOutlet UIView *landscapeView;
    IBOutlet UIView *portraitView;
    

    and to @implementation

    - (void) viewDidLoad {
    self.view.frame = [[UIScreen mainScreen] applicationFrame];
      landscapeView.autoresizesSubviews = NO;  <- IMPORTANT!
      portraitView.autoresizesSubviews = NO;   <- IMPORTANT!
    }
    - (BOOL)shouldAutorotateToInt .... {
      if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight) self.view = landscapeView;
      else if ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) self.view = portraitView;
      return YES;
    }
    

提交回复
热议问题