【问题标题】:iOS5,presentModalViewController presenting new view incorrectlyiOS5,presentModalViewController 显示新视图不正确
【发布时间】:2013-06-04 03:31:31
【问题描述】:

我的应用主要支持iOS6+。在考虑iOS5时,我添加了以下判断。

 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0) { 
    self.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:readerViewController animated:YES completion:NULL];
 }
 else {
    self.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentModalViewController:readerViewController animated:YES];
}

但是,模式视图在我的横向应用程序中垂直显示。我的意思是,我的应用是横向的,模态视图只是“躺在”那里,而不是我设置的全屏,只是覆盖部分屏幕,而未覆盖的是黑色。

我想知道是否有人可以提供帮助。谢谢转发。

【问题讨论】:

    标签: objective-c ios5 presentmodalviewcontroller


    【解决方案1】:

    丁香:- tia 说的是正确的。你不需要担心版本。我认为你没有为 ModalView 设置所需的视图 Oreintation 的方向。

    意味着,如果您的 mainViewController(您从中呈现 ModalView)仅支持横向模式,那么在 modalViewController 中,您必须设置方向,限制为仅在横向视图中呈现。

    您应该在 modalViewController 中编写 mainViewController 中编写的 Orientation 代码。

    这些方法:-

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
        //    return YES;
    
    }
    
    -(BOOL)shouldAutorotate{
        return YES;
    }
    
    -(NSUInteger)supportedInterfaceOrientations{
        return UIInterfaceOrientationMaskLandscape;
    }
    

    如果它不能解决您的问题,如果它确实有帮助,请回复,您知道该怎么做;)。

    【讨论】:

    • 我确实有你楼上提到的方法,这个问题是不久前的自动旋转问题的延伸。父视图支持横向和模态视图所有方向。在 iOS6+ 中,我从其父视图呈现了一个模态视图,它工作正常。在iOS5中,问题就出来了。如果不是版本问题,那还有什么问题?你能想到吗?
    【解决方案2】:

    首先,presentViewController:animated:completion: 已提供since iOS 5.0,因此您不必担心版本。如果你真的想检查方法的可用性,你应该使用

    if ([self respondToSelector:@selector(presentViewController:animated:completion:)])
    

    对于模态视图,您需要在显示的控制器上设置modalTransitionStylemodalPresentationStyle,例如readerViewController 在你的情况下。所以你的代码应该是

    readerViewController.modalTransitionStyle = UIModalPresentationFullScreen;
    readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentModalViewController:readerViewController animated:YES completion:NULL];
    

    【讨论】:

    • 您的方式确实呈现模态视图。但重要的是它只是“撒谎”在那里,而不是我设置的全屏。我也试过 [self.presentingViewController presentViewController:readerViewController animated:YES completion:NULL];虽然它不起作用。
    • 也许我错过了一些细节?父视图支持横向和模态视图所有方向。在 iOS6+ 中,我从其父视图呈现了一个模态视图,它工作正常。在iOS5中,问题就出来了。如果不是版本问题,那还有什么问题?你能想到吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-12
    • 1970-01-01
    相关资源
    最近更新 更多