gpt4 book ai didi

ios - 如何使用 Objective C 更改基于设备方向的 UIView 约束?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:58:59 25 4
gpt4 key购买 nike

我正在尝试为 portraitlandscape 创建具有多个 View 的 iOS storyboard。我创建的所有 Storyboard constraintsautolayout

现在我的问题是肖像,我需要像下面的肖像图像一样显示。这是我通过使用 Storyboard约束完成的。

对于横向需要显示第一 View (红色) 和底栏只有其他我已通过硬编码隐藏。但我不知道如何将红屏第一个 View 的全高扩展到底部栏顶部。

注意:这是通用应用程序。

- (void) orientationChanged:(NSNotification *)note
{
UIDevice * device = note.object;
switch(device.orientation)
{
case UIDeviceOrientationPortrait:
/* start special animation */
NSLog(@"Portrait");
self.namelist_tableview.hidden = NO;// ORANGE VIEW
break;

case UIDeviceOrientationLandscapeRight:
/* start special animation */
NSLog(@"Landscape");
self.namelist_tableview.hidden = YES;// ORANGE VIEW
break;

case UIDeviceOrientationLandscapeLeft:
/* start special animation */
NSLog(@"Landscape");
self.namelist_tableview.hidden = YES;// ORANGE VIEW
break;

default:
break;
};
}

enter image description here

最佳答案

很简单,在intefacebuilder中添加constraints for portrait mode, 为横向模式添加约束。接下来为所有约束创建一个导出。在设备更改方向事件中执行此操作

如果您处于横向模式

+将纵向的事件约束设置为 false (constraint.active = NO)

+将景观约束的事件设置为真(constraint.active = YES)

如果您处于纵向模式

+将景观约束的事件设置为假(constraint.active = NO)

+将纵向约束的事件设置为真(constraint.active = YES)

关于ios - 如何使用 Objective C 更改基于设备方向的 UIView 约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34202300/

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