0

enter image description here

Im wanting to setup my view within the storyboard so it lays out like the above image. The view has 2 seperate sections when landscape the share 50/50 horizontally then when portrait it rotates to 50/50 vertically.

What is the most appropriate way to set this up inside xcode interface builder? Can I use constraints to achieve this? This will need to be designed so it will scale to ipad and iphone as well.

Matt
  • 3,305
  • 11
  • 54
  • 98
  • Unfortunately, iPad's only have one type of layout for both landscape and portrait. I don't think there is a way to do what you want to do through the storyboard. Check out the following, maybe it'll help -> [http://stackoverflow.com/questions/26633172/sizing-class-for-ipad-portrait-and-landscape-modes/28268200#28268200](http://stackoverflow.com/questions/26633172/sizing-class-for-ipad-portrait-and-landscape-modes/28268200#28268200). – RPK Feb 16 '16 at 01:31

1 Answers1

0

I build a project to test. It works, check the screenshot

iPad in Portrait iPad in Portrait iPad in Landscape iPad in Landscape

It can't be done in Storyboard, because iPad only got one layout in Storyboard. but it's very simple to achieve what you need programmatically .

//ViewController.m
#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) UIView *firstView;
@property (nonatomic, strong) UIView *secondView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.firstView = [[UIView alloc] initWithFrame:CGRectZero];
    self.firstView.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.firstView];
    self.secondView = [[UIView alloc] initWithFrame:CGRectZero];
    self.secondView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:self.secondView];
    [self setupSubViewLayout];
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [self setupSubViewLayout];
}

- (void)setupSubViewLayout {
    CGFloat viewWidth = self.view.frame.size.width;
    CGFloat viewHeight = self.view.frame.size.height;
    CGRect firstRect;
    CGRect secondRect;
    if (viewWidth > viewHeight) {
        firstRect = CGRectMake(0, 0, viewWidth/2.0, viewHeight);
        secondRect = CGRectMake(viewWidth/2.0, 0, viewWidth/2.0, viewHeight);
    }else {
        firstRect = CGRectMake(0, 0, viewWidth, viewHeight/2.0);
        secondRect = CGRectMake(0, viewHeight/2.0, viewWidth, viewHeight/2.0);
    }
    self.firstView.frame = firstRect;
    self.secondView.frame = secondRect;
}
ronan
  • 1,611
  • 13
  • 20