Vas*_*gin 3 objective-c autolayout swift ios-autolayout
我有两种看法:toastView和view。toastView是 的子视图view。我想toastView在 y 轴上定位view高度的 80%。如何在代码中使用常量来做到这一点?
我假设有一个类似的方法:
[toastView.topAnchor constraintEqualToAnchor:view.heightAnchor multiplier:0.8].active = YES;
Run Code Online (Sandbox Code Playgroud)
但我不能混合NSLayoutDimension(宽度和高度)和NSLayoutYAxisAnchor(X 和 Y)
这就是它在设计中的样子:

这里的技巧是将的顶部toastView设置为等于的底部,self.view并乘以:0.8
Objective-C:
[NSLayoutConstraint constraintWithItem: toastView attribute: NSLayoutAttributeTop
relatedBy: NSLayoutRelationEqual toItem: self.view
attribute: NSLayoutAttributeBottom multiplier: 0.8 constant: 0].active = YES;
Run Code Online (Sandbox Code Playgroud)
迅速:
NSLayoutConstraint(item: toastView, attribute: .top, relatedBy: .equal,
toItem: self.view, attribute: .bottom, multiplier: 0.8, constant: 0).isActive = true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1144 次 |
| 最近记录: |