2016-05-03 33 views
0

我试图创建上2次视图控制器,它看起来就像在IB enter image description here如何使具有2次覆盖屏幕,而不是重叠

enter image description here

屏幕但他们只在iPhone 5s上以这种方式行事 在其他情况下,它看起来像在横向上的图像上显示的方式。我使用大小类来为不同的屏幕方向设置约束。

enter image description here

,这是它看起来iPhone 6S的方式加enter image description here

回答

0

所以这个问题似乎是早于iPhone 6+的iPhone在横向上具有wCompact hCompact大小类。你应该记住不要使用像wCompact hAny这样的大小类,因为它们会覆盖该紧凑大小类。

所以,实际上,你在这种情况下需要的是创建3个大小类: wCompact hRegular - 所有人像 wCompact hCompact - iPhone手机比6+ wRegular hCompact更早 - 所有其他

1

任何/紧凑意味着紧凑型宽任何电话,其中iPhone的小于6+的。您需要为Regular/Compact设置约束条件,以便在Portrait中为6+以外的iPhone设置约束条件。

+0

我这样做,但它并没有帮助(( – AOY

+0

)如果你删除任何大小的任何类型的宽度或任何高度的限制?只是正确定义的? – choli

0

你应该给喜欢约束,

top, bottom, leading and trailing到两个视图。

然后选择两个视图并给出equal height约束,您将得到想要的结果。

你可以在any any中给它。它将适用于每个方向。

希望这将有助于:)

+0

我需要这些意见是一个在另一个肖像和特殊设计为iPad的,所以任何任何都不会帮助(( 我确实使用这种约束,但他们不工作((( – AOY

+0

这是不是强制保留任何任何。我认为这种限制工作在任何时候y大小班。尝试一下。 – Lion

+0

问题是,他们只是不工作(( 我可以给你的源代码,如果你愿意 – AOY

1

这种事情是比较容易与UIStackView

  1. 请选择您的两个视图。
  2. 点击右下方的图标以在它们周围创建UIStackView。
  3. 将新的UIStackView设置为水平或垂直方向。
  4. 将其固定在封闭视图中。你完成了!

有一个good tutorial here;我强烈建议你在做一些艰难的工作之前先设置一些堆栈视图。

+0

谢谢。我一直在想,但我担心的事实,只能从iOS 9.0。在早期版本的 – AOY

+1

上运行的设备中,有15%听起来是正确的;但有多少15%会购买你的产品?对于大多数人来说,支持除当前操作系统以外的任何东西都不值得进行额外的开发/测试/支持特别是在OS 10或iOS X或任何他们称之为的周期的这一阶段,将在未来几周内推出...... –

+0

谢谢你)我会做你的建议) – AOY

0

添加到您的的viewController

UIView *firstView = [[UIView alloc] init];  
self.navigationController.navigationBar.translucent = false; 
firstView.backgroundColor = [UIColor redColor]; 

firstView.translatesAutoresizingMaskIntoConstraints = false; 
[self.view addSubview:firstView]; 
    NSLayoutConstraint *topFirstViewYConstraint = [ 

NSLayoutConstraint constraintWithItem的viewDidLoad中方法:的firstView属性:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view属性:NSLayoutAttributeTop 乘数:1.0F 常数: 0.0f

];

NSLayoutConstraint * centerFirstViewHeightConstraint = [ NSLayoutConstraint constraintWithItem:的firstView 属性:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:自我。查看 属性:NSLayoutAttributeHeight 乘数:0.5f 常数:0.0 ];

NSLayoutConstraint * centerFirstViewWidthConstraint = [ NSLayoutConstraint constraintWithItem:的firstView 属性:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view 属性:NSLayoutAttributeWidth乘数:1.0F常数:0.0F ]; [super.view addConstraints:@ [topFirstViewYConstraint,centerFirstViewHeightConstraint,centerFirstViewWidthConstraint]];

UIView *secondView = [[UIView alloc] init]; 
secondView.backgroundColor = [UIColor greenColor]; 
secondView.translatesAutoresizingMaskIntoConstraints = false; 
[self.view addSubview:secondView]; 
NSLayoutConstraint *topSecondViewYConstraint = [ 

NSLayoutConstraint constraintWithItem:secondView 属性:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:的firstView 属性:NSLayoutAttributeBottom 乘数:1.0F 常数:0.0F ]; NSLayoutConstraint * centerSecondViewHeightConstraint = [ NSLayoutConstraint constraintWithItem:secondView 属性:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view 属性:NSLayoutAttributeHeight 乘数:0.5F 常数:0.0 ]; NSLayoutConstraint * centerSecondViewWidthConstraint = [ NSLayoutConstraint constraintWithItem:secondView 属性:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view 属性:NSLayoutAttributeWidth 乘数:1.0F 常数:0.0F ]; [super.view addConstraints:@ [topSecondViewYConstraint,centerSecondViewHeightConstraint,centerSecondViewWidthConstraint]];