Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在xcode中在视图上布置相等的部分_Ios_Objective C_Iphone_Xcode_Interface Builder - Fatal编程技术网

Ios 在xcode中在视图上布置相等的部分

Ios 在xcode中在视图上布置相等的部分,ios,objective-c,iphone,xcode,interface-builder,Ios,Objective C,Iphone,Xcode,Interface Builder,我想在故事板中设置我的视图,使其布局如上图所示。当横向50/50共享时,视图有两个独立的部分,当纵向50/50共享时,视图垂直旋转到50/50 在xcode interface builder中设置此功能最合适的方法是什么?我可以使用约束来实现这一点吗?这需要进行设计,以便能够扩展到ipad和iphone。我构建了一个项目进行测试。工作正常,请查看屏幕截图 肖像中的iPad 景观中的iPad 这不能在情节提要中完成,因为iPad在情节提要中只有一个布局。 但以编程方式实现所需的功能非常简单 /

我想在故事板中设置我的视图,使其布局如上图所示。当横向50/50共享时,视图有两个独立的部分,当纵向50/50共享时,视图垂直旋转到50/50


在xcode interface builder中设置此功能最合适的方法是什么?我可以使用约束来实现这一点吗?这需要进行设计,以便能够扩展到ipad和iphone。

我构建了一个项目进行测试。工作正常,请查看屏幕截图

肖像中的iPad 景观中的iPad

这不能在情节提要中完成,因为iPad在情节提要中只有一个布局。 但以编程方式实现所需的功能非常简单

//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;
}

不幸的是,iPad只有一种横向和纵向布局。我不认为有一种方法可以通过故事板来做你想做的事情。查看以下内容,也许会有所帮助->。