【发布时间】:2014-07-01 23:09:53
【问题描述】:
我刚刚开始尝试使用 AutoLayout,但不太明白。
谁能告诉我如何以编程方式将视图固定到其父视图,以使视图边缘和父视图边缘之间的空间为 0。(本质上,我想要横屏时视图仍然覆盖屏幕)
谢谢
最后,我是这样解决的:(vc.view 是子视图,self.view 是父视图)
/* pin Left of child to left of parent */
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:vc.view
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:0]];
/* pin Right of child to right of parent */
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:vc.view
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:0]];
/* pin top of child to bottom of nav bar(or status bar if no nav bar) */
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:vc.view
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.topLayoutGuide
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0]];
/* pin Top of nav bar to bottom of child view */
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.bottomLayoutGuide
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:vc.view
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0]];
【问题讨论】:
-
我认为这应该会有所帮助。 stackoverflow.com/questions/8156799/…
标签: xcode ios7 xcode5 autolayout