gpt4 book ai didi

iphone - 在界面旋转时对 UIView 到底做了什么?

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

谁能解释一下 iOS 在界面旋转方面的作用。我遇到了一个布局问题,其中一个 View 在旋转 iPhone 后消失了。似乎 View 设置了一个新的框架、边界或其他什么,不知道。无论如何,一旦布局问题永远消失,界面就会旋转。所以必须在界面旋转时为 View 设置一些东西。

我从 NIB 文件加载 View 并用导航 Controller 显示它:

BirthdayReminderWidgetConfigViewController *vc = [self.storyboard
instantiateViewControllerWithIdentifier:@"BirthdayConfigController"];
self.navigationController pushViewController:vc animated:true];

也许我必须做一些设置才能在不旋转界面的情况下正确显示 View 。

从 nib 文件加载的 View 存在布局问题,如下所示:

该项目包含一个 MainStoryboard。在其中,我从 nib 文件加载 View 。

NSArray *xib = [[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil];
self.configViewController = [xib objectAtIndex:0];

Storyboard有一个导航 Controller ,加载的 View 如下所示:

    if (currentWidgetConfigViewController != nil)
{
[self.navigationController pushViewController:currentWidgetConfigViewController animated:true];
}

所以在我看来没有错? (第一个问题)但是现在问题来了。

我设计的是:

enter image description here

iOS 的作用如下

enter image description here

控件没有安排好。

除此之外,我用新 View 上的按钮打开了一个带有该代码的 PeoplePicker:

[self presentViewController:self.picker animated:YES completion:nil];

使用 [self.picker dismissViewControllerAnimated:true completion:nil]; 关闭人员选择器后,我得到了这个结果:

enter image description here

那么这里出了什么问题呢?

最佳答案

在您的 View 中覆盖 -setFrame:-setBounds: 以查看会发生什么:

- (void) setFrame: (CGRect) newFrame
{
NSLog(@"New frame: %@", NSStringFromCGRect(newFrame));
[super setFrame:newFrame];
}

此外,transform 通常会在旋转过程中发生变化。 Orientation Zoo可能会有所帮助,这是一个示例 Xcode 项目,展示了在各种旋转用例中发生的情况。不过好久没碰了,不知道还能不能用。

关于iphone - 在界面旋转时对 UIView 到底做了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12577101/

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