如何将视图滑出iPhone X的可见区域?

时间:2018-03-02 14:23:21

标签: ios autolayout nslayoutconstraint iphone-x safearealayoutguide

当导航栏隐藏时,我希望视图在可见区域之外向上滑动。

视图附加到safeAreaLayoutGuide:

topConstraint = myView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor)

要将其滑出,约束会更改:

topConstraint.constant = hidden ? -(myView.frame.height) : 0

这适用于iPhone 7但不适用于iPhone X.隐藏导航时,view.topAnchorview.safeAreaLayoutGuide.topAnchor之间存在差距。

最简单的方法是将视图附加到导航栏的底部锚点,但尝试此操作时应用程序崩溃:

topConstraint = myView.topAnchor.constraint(equalTo: navigationController!.navigationBar.bottomAnchor)

那么如何将myView滑出可见区域呢?

1 个答案:

答案 0 :(得分:0)

替换以下行

<mat-select style="min-width: 200px;" placeholder="" [(value)]="element.acc_desc" >
   <mat-option *ngFor="let dep of acc_desc " [value]="dep.acc_desc" >
     {{ dep.acc_desc }}
   </mat-option>
</mat-select>

topConstraint = myView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor)