Ign*_*ioC 7 uiviewcontroller ipad screen-rotation presentmodalviewcontroller
我在ipad上有uiviewcontroller这个配置:
shouldAutorotate (true)
supportedInterfaceOrientations (UIInterfaceOrientationMaskAll)
在里面willRotateToInterfaceOrientation我执行一些技巧来调整我的界面.
从这个控制器的一个孩子,我展示了一个带有这个-poor-代码的QuickLookController.
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:previewController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
但是,如果我旋转我的ipad方法willRotateToInterfaceOrientation没有被调用,所以我无法做到调整界面的技巧.
有人可以解释我或给我一些建议吗?谢谢
Moi*_*med 13
原因: 这个问题可能有很多种可能性.
1)如果你的观点的viewController是subView一些其他的rootViewController是不是navigationController,那么有可能是旋转呼叫不会传播到子视图的控制器机会.
2)在某处我读到如果Super在需要的地方没有正确调用方法那么它可能是旋转问题的原因,这意味着视图堆栈中与自动旋转相关的所有ViewControllers必须super在方法实现中调用方法(即调用[super viewDidLoad]来自ViewController的viewDidLoad).
您可以使用以下技巧来处理方向更改.
在viewWillAppear中注册通知程序.
-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];}
Run Code Online (Sandbox Code Playgroud)
方向更改将通知以下功能.
- (void)orientationChanged:(NSNotification *)notification{
[self handleOrientation:[[UIApplication sharedApplication] statusBarOrientation]];}
Run Code Online (Sandbox Code Playgroud)
这将调用以下方法,您可以在其中处理方向更改.
- (void) handleOrientation:(UIInterfaceOrientation) orientation {
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
//handle the portrait view
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
//handle the landscape view
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9873 次 |
| 最近记录: |