gpt4 book ai didi

ios - 不同的纵向和横向自动布局约束 : where to set them when the device is firSTLy in landscape?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:11:31 24 4
gpt4 key购买 nike

我已经将 NSLayoutConstraint 设置为 IBOutlet,并且我在 storyboardIB 中设置了值> 用于纵向。当我以纵向运行应用程序然后将设备旋转为横向时,我管理约束更新。但是当我运行应用程序时,设备已经处于横向状态,约束具有纵向值。

加载 View Controller 并显示 View 时,我应该在哪里检查设备的当前方向,并根据该方向设置适当的约束?

谢谢

最佳答案

您最初可以在 viewDidLoad 方法中保留一个条件

if(UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])){
// Apply Portrait Constraints
}
else{
// Apply Landscape Constraints
}

稍后当用户改变方向时,您可以检查下面的方法并应用相同的条件

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){
// Apply Portrait Constraints
}
else{
// Apply Landscape Constraints
}
}

关于ios - 不同的纵向和横向自动布局约束 : where to set them when the device is firSTLy in landscape?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33604402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com