gpt4 book ai didi

iphone - 在 viewDidLoad 中触发旋转

转载 作者:行者123 更新时间:2023-11-28 20:30:06 25 4
gpt4 key购买 nike

我遇到了一些布局问题,当我以纵向模式启动我的应用程序然后将其转为横向模式时,之后打开的 View 返回错误的旋转值。

例如,我在从纵向模式旋转后以横向模式打开一个 View ,当我记录旋转时它仍然返回纵向模式:

NSLog(@"%u", [[UIDevice currentDevice] orientation]); // 4
NSLog(@"%f / %f", self.view.frame.size.width, self.view.frame.size.height); // 748.000000 / 1024.000000

当我将 iPad 旋转到纵向模式并返回横向模式时,它会返回正确的尺寸

NSLog(@"%u", [[UIDevice currentDevice] orientation]); // 1
NSLog(@"%f / %f", self.view.frame.size.width, self.view.frame.size.height); // 1024.000000 / 704.000000

我需要做些什么才能使新添加的 View 适应旋转吗?

最佳答案

在 viewWillAppear 方法中设置 View 的新框架。这会将所有项目设置为正确的大小,如果您使用导航 Controller ,这将在推送和弹出 View 时起作用。

关于iphone - 在 viewDidLoad 中触发旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12488043/

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