gpt4 book ai didi

iphone - 呈现 subview Controller 时,父 View Controller 不旋转

转载 作者:可可西里 更新时间:2023-11-01 05:04:51 25 4
gpt4 key购买 nike

我有一个支持所有四个方向的父 View Controller 。它呈现一个 subview Controller ,如果在呈现 subview Controller 时旋转设备,然后您关闭 subview Controller ,则父 View Controller 不会正确旋转。这是我在父 View Controller 中用于旋转的代码:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {

newestIssueCoverImageButton.frame = CGRectMake(40, 20, 688, 865);
shadow.frame = CGRectMake(40, 20, 688, 865);
recordView.frame = CGRectMake(0, 44, 768, 916);
classifiedsWebView.frame = CGRectMake(0, 44, 768, 916);

} else {

newestIssueCoverImageButton.frame = CGRectMake(269, 20, 486, 613);
shadow.frame = CGRectMake(269, 20, 486, 613);
recordView.frame = CGRectMake(0, 44, 1024, 660);
classifiedsWebView.frame = CGRectMake(0, 44, 1024, 660);

}

虽然没有使用此代码,但家长查看了,我只是旋转了设备。如何调用此代码并确保当用户当前正在查看子项时父 View Controller 正确旋转?感谢您的帮助。

最佳答案

来自 Apple 的文档:

If a view controller is not visible when an orientation change occurs, then the rotation methods are never called. However, the viewWillLayoutSubviews method is called when the view becomes visible. Your implementation of this method can call the statusBarOrientation method to determine the device orientation.

我添加了一个BOOL来跟踪何时不是顶层的viewController,然后:

- (void)viewWillLayoutSubviews {

if (notTopController) {

[self willRotateToInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation] duration:0];
[self willAnimateRotationToInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation] duration:0];

notTopController = NO;

}

到目前为止对我来说效果很好。

关于iphone - 呈现 subview Controller 时,父 View Controller 不旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9455090/

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