【问题标题】:Modal View Controller making background black模态视图控制器使背景变黑
【发布时间】:2012-06-06 05:34:54
【问题描述】:

我正在从视图控制器启动模态视图控制器。模态视图控制器中的所有内容都显示正常,除了父视图控制器变黑。当模态视图控制器被解除时,父级被绘制。谁能指出我哪里出错了?这是我正在使用的代码:

modalVC.modalPresentationStyle = UIModalPresentationFormSheet;
self.navigationController = [[UINavigationController alloc] initWithRootViewController: modalVC];

[currentViewController presentModalViewController: self.navigationController animated: YES];
self.navigationController.view.frame = CGRectMake(200, 200, 320, 540);

【问题讨论】:

    标签: objective-c xcode modalviewcontroller


    【解决方案1】:

    我终于找到了问题所在。这是我的错误。

    这是罪魁祸首:

    self.navigationController.view.frame = CGRectMake(200, 200, 320, 540);
    

    应该是:

    self.navigationController.view.superview.frame = CGRect(200,200,320, 540);
    

    【讨论】:

    • 我在 viewDidLoad [self.view setTranslatesAutoresizingMaskIntoConstraints:NO]; 中执行此操作,我猜它会将视图缩小到 0,0。
    【解决方案2】:

    是因为这条线。

    modalVC.modalPresentationStyle = UIModalPresentationFormSheet;
    

    来自UIViewController Class Reference(强调我的):

    UIModalPresentationFormSheet

    呈现的视图的宽度和高度小于屏幕的宽度和高度,并且视图在屏幕上居中。如果设备处于横向并且键盘是可见的,则视图的位置会向上调整,以使视图保持可见。 所有未覆盖的区域都会变暗,以防止用户与其互动。

    【讨论】:

    • 非常感谢您的回复。其他区域没有变暗,只是在弹出框消失之前变黑。
    • 我终于找到了问题所在。这是我的错误。这是罪魁祸首:self.navigationController.view.frame = CGRectMake(200, 200, 320, 540); 应该是:self.navigationController.view.superview.frame = CGRect(200,200,320, 540);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2015-02-24
    • 2015-02-20
    • 2021-09-23
    • 1970-01-01
    • 2021-04-28
    • 1970-01-01
    相关资源
    最近更新 更多