gpt4 book ai didi

ipad - willRotateToInterfaceOrientation 未从呈现的 View Controller 中调用

转载 作者:行者123 更新时间:2023-12-02 19:44:10 27 4
gpt4 key购买 nike

我在 iPad 上有 uiviewcontroller,配置如下:

shouldAutorotate (true)
supportedInterfaceOrientations(UIInterfaceOrientationMaskAll)
willRotateToInterfaceOrientation 中,我执行了一些技巧来调整我的界面。

从这个 Controller 的子 Controller 中,我显示了一个带有这个糟糕代码的 QuickLookController。

[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:previewController animated:YES completion:nil];

但是,如果我旋转 ipad,则不会调用 willRotateToInterfaceOrientation 方法,因此我无法调整界面。

有人可以解释我或给我一些建议吗?谢谢

最佳答案

原因:这个问题可能有很多种可能。

1) 如果您的 View 的 viewController 是其他某个 rootViewControllersubView,而该 rootViewController 不是 navigationController,那么旋转调用可能不会传播到 subview 的 Controller 。

2)我在某处读到,如果在需要的地方没有正确调用Super方法,那么它可能是导致旋转问题的原因,这意味着 View 堆栈中与自动旋转必须调用方法实现中的 super 方法(即从 ViewController 的 viewDidLoad 调用 [super viewDidLoad])。

您可以使用以下技巧来处理方向变化。

在 viewWillAppear 中注册通知程序。

-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];}

方向变化将通知以下函数。

- (void)orientationChanged:(NSNotification *)notification{
[self handleOrientation:[[UIApplication sharedApplication] statusBarOrientation]];}

它将调用下面的方法,您可以在其中处理方向更改。

   - (void) handleOrientation:(UIInterfaceOrientation) orientation {

if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
//handle the portrait view
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
//handle the landscape view
}
}

关于ipad - willRotateToInterfaceOrientation 未从呈现的 View Controller 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14170404/

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