如何为横向模式或纵向模式设置应用程序控件?

时间:2015-09-23 10:11:54

标签: ios uiview landscape

我知道自动布局可用于在方向改变时使尺寸和位置保持一致。当方向改变时,是否可以完全改变布局?意味着当设备旋转到横向模式时,所有控制器都可以更改其位置并相应地设置设备模式。这可以用于iPhone 4,5,6,6 plus的所有设备。没有使用故事板。任何人都可以帮我解决这个问题。提前谢谢。

1 个答案:

答案 0 :(得分:0)

****查看超级视图 [self addEdgeConstraint:NSLayoutAttributeLeft superview:self.view subview:subView];

[self addEdgeConstraint:NSLayoutAttributeRight superview:self.view subview:subView];

[self addEdgeConstraint:NSLayoutAttributeTop superview:self.view subview:subView];

[self addEdgeConstraint:NSLayoutAttributeBottom superview:self.view subview:subView];

- (void)addEdgeConstraint:(NSLayoutAttribute)edge superview:(NSView *)superview subview:(NSView *)subview

{     [superview addConstraint:[NSLayoutConstraint constraintWithItem:subview attribute:edge relatedBy:NSLayoutRelationEqual toItem:superview attribute:edge multiplier:1 constant:0]];

}

表示视图之间的垂直间距

NSMutableArray * newVerticalConstraints = [NSMutableArray array];

[newVerticalConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[view1]” options:0 metrics:nil views:NSDictionaryOfVariableBindings(viewMainBanner)]];

[newVerticalConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:[NSString stringWithFormat:@"V:[view1]-%d-[view2]”,10] options:0 metrics:nil views:NSDictionaryOfVariableBindings(view1, view2)]];

[newVerticalConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:[NSString stringWithFormat:@"V:[view2]-%d-[view3]”,10]  options:0 metrics:nil views:NSDictionaryOfVariableBindings(view2, view3)]];

[newVerticalConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[view3]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(view3)]];

[self.view addConstraints:newVerticalConstraints];***

///而不是v我们可以使用'H'作为水平间距