willRotateToInterfaceOrientation未从呈现的viewcontroller中调用 [英] willRotateToInterfaceOrientation not being called from presented viewcontroller
问题描述
我在ipad上 uiviewcontroller 使用此配置:
I have uiviewcontroller on ipad with this configuration:
shouldAutorotate(true)
supportedInterfaceOrientations( UIInterfaceOrientationMaskAll)
和里面 willRotateToInterfaceOrientation
我执行一些技巧来调整我的界面。
shouldAutorotate (true)
supportedInterfaceOrientations (UIInterfaceOrientationMaskAll)
and inside willRotateToInterfaceOrientation
i perform some trick to adjust my interface.
从这个控制器的一个孩子,我展示了一个带有这个-poor码的QuickLookController。
From a child of this controller I show a QuickLookController with this -poor- code.
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:previewController animated:YES completion:nil];
但如果我旋转我的ipad方法 willRotateToInterfaceOrientation
没有被调用,所以我无法调整界面。
But if I rotate my ipad the method willRotateToInterfaceOrientation
not being called, So I cannot do the trick to adjust the interface.
有人可以解释我或给我一些建议吗?谢谢
Someone can explain me or given me some advices? thanks
推荐答案
原因:
这个问题可能有很多种可能性。
Reason : There may be many possibilities to this problem.
1)如果你的视图的 viewController
是一个 subView
的一些其他 rootViewController
这不是 navigationController
,那么旋转调用可能没有传播到subView的控制器。
1) If your view's viewController
is a subView
of some other rootViewController
which is not a navigationController
, then there might be chances that rotation call is not propagating to the subView's controller.
2)在某处我读到如果 Super
方法在需要的地方没有被正确调用那么它可能是旋转原因问题,这意味着视图堆栈中与自动旋转相关的所有ViewControllers必须在方法实现中调用 super
方法(即调用 [来自ViewController的
。 viewDidLoad
)的超级viewDidLoad]
2) Somewhere I read that if Super
methods are not called properly where it is needed then it might be the cause of rotation problem, which means that all ViewControllers in view stack which are related to the autorotation must call the super
methods in method implementations (i.e. calling [super viewDidLoad]
from the ViewController's viewDidLoad
).
你可以使用以下技巧来处理方向变化。
在viewWillAppear中注册通知程序。
Register a notifier in viewWillAppear.
-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];}
方向更改将通知以下功能。
The orientation change will notify the below function.
- (void)orientationChanged:(NSNotification *)notification{
[self handleOrientation:[[UIApplication sharedApplication] statusBarOrientation]];}
这将调用以下方法,你可以处理方向更改。
which will call the below method where you can handle the orientation changes.
- (void) handleOrientation:(UIInterfaceOrientation) orientation {
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
//handle the portrait view
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
//handle the landscape view
}
}
这篇关于willRotateToInterfaceOrientation未从呈现的viewcontroller中调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!