用自动布局动画UIView

时间:2018-09-17 15:10:19

标签: objective-c xcode autolayout storyboard iphone-x

当我尝试为iPhoneX的UIView设置动画时,自动布局出现了一些问题。如您在第一张图片中所见,我的UIView已关闭,所以我得到了想要的...

enter image description here

结果

enter image description here

在第二个图像中,我尝试打开UIView,但是您可以看到空间仍然在底部,而不是在iPhone 7上,而且没有剩余的空间..

enter image description here

如何扩展uiview的长度以覆盖底部缺少的空间?

我已经尝试过从Superview的“安全区域”中更改我的第一项,但这给我带来了另一个问题,因为当我的uiview关闭时,与iphone 7 plus相比,它下降得太多了……

enter image description here

结果

enter image description here


我需要的是这样的结果

enter image description here enter image description here

你能帮我吗?

1 个答案:

答案 0 :(得分:0)

已解决self.view.safeAreaInset.bottom ...

当UIView关闭时,我以这种方式对约束(loginPanelBottomConstraint)进行动画处理:

[UIView animateWithDuration:.3 animations:^{
            self.loginPanelBottomConstraint.constant = 0 + self.view.safeAreaInsets.bottom;
            [self.view layoutIfNeeded];
        }];

打开面板时:

[UIView animateWithDuration:.3 animations:^{
                self.loginPanelBottomConstraint.constant = 245
                [self.view layoutIfNeeded];
            }];