Ios 在xcode中在视图上布置相等的部分
我想在故事板中设置我的视图,使其布局如上图所示。当横向50/50共享时,视图有两个独立的部分,当纵向50/50共享时,视图垂直旋转到50/50Ios 在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在情节提要中只有一个布局。 但以编程方式实现所需的功能非常简单 /
在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只有一种横向和纵向布局。我不认为有一种方法可以通过故事板来做你想做的事情。查看以下内容,也许会有所帮助->。