gpt4 book ai didi

ios - 旋转时在主从 View 和其他 View Controller 之间切换?

转载 作者:行者123 更新时间:2023-11-29 04:02:58 25 4
gpt4 key购买 nike

我现在正在测试一个适用于 iPad 的应用程序。基本上我正在使用主细节应用程序的模板,并有另一个portraitViewController。现在,当应用程序以纵向模式启动时,我希望它仅显示 PortraitViewController,当设备旋转时,例如横向模式,我希望仅显示 master-detailViewController。执行此操作的最佳方法是什么。

我正在测试单 View 应用程序的示例代码,但主从 View 拒绝隐藏:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
self.view = self.portrait;
self.view.transform = CGAffineTransformIdentity;
self.view.transform =
CGAffineTransformMakeRotation(degreesToRadians(0));
self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0);
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
self.view = self.landscape;
self.view.transform = CGAffineTransformIdentity;
self.view.transform =
CGAffineTransformMakeRotation(degreesToRadians(−90));
self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0);
}
else if (interfaceOrientation ==
UIInterfaceOrientationLandscapeRight) {
self.view = self.landscape;
self.view.transform = CGAffineTransformIdentity;
self.view.transform =
CGAffineTransformMakeRotation(degreesToRadians(90));
self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0);
} }

最佳答案

View Controller 不应该像这样实时更改其 View 。您没有看到任何事情发生,因为 View Controller 的旧 View 仍在界面中;您没有将其从界面中删除。你也不应该这样做。实现这一点的方法是替换 View Controller ;使用不同的 View Controller 和不同的 View 。

您从主从 View Controller 开始,因此应用程序的 Root View Controller 是 UISplitViewController。它的 View (分割 View )看起来就是您要删除的 View 。因此,您必须将 UISplitViewController 替换为窗口的 rootViewController

但这真是一个巨大的痛苦。我认为您可能会更高兴在纵向时将模态(呈现) View Controller 放在所有内容前面。

这是一个可下载的示例项目,它呈现一个 View Controller 以响应设备旋转:

https://github.com/mattneub/Programming-iOS-Book-Examples/tree/master/ch19p609rotationForcingModalView

关于ios - 旋转时在主从 View 和其他 View Controller 之间切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15650015/

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