没有调光的ModalViewController /禁用当前的viewcontroller

时间:2012-07-09 19:30:42

标签: objective-c ios modalviewcontroller

我将aNavController显示为特定帧CGRectMake(40,50,400,500)中的modalViewController。哪个工作正常。现在我在self中有一个按钮(在其上显示modalViewController的viewcontroller),按下该按钮我需要在aNavController上显示一些消息。但问题是当我呈现modalViewController时。整个屏幕区域变暗/禁用。因此,无法触摸/单击该按钮。

这是我提供视图控制器的代码。我想,我在这里错过了一些东西。请帮忙。提前谢谢。

aNavController.modalPresentationStyle = UIModalPresentationFormSheet;
anavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:aNavController animated:YES];
aNavController.view.superview.frame = CGRectMake(40,50, 400, 500);

3 个答案:

答案 0 :(得分:1)

presentModalViewController创建一个模态对话框。当模态视图控制器启动时,在取消模态视图之前,用户不能对父视图执行任何操作。

答案 1 :(得分:0)

问题是您在UIAlertView调用presentModalViewController的委托方法UIAlertView中的模态视图的同时实例化clickedButtonAtIndex

像这样:

- (IBAction)clickedMyButton:(id)sender
{
    UIAlertView *alertView = [[UIAlertView alloc]
                 initWithTitle: @"Title"
                 message: @"Message"
                 delegate:self
                 cancelButtonTitle:@"Close Button"
                 otherButtonTitles:@"Modal Button", @"Some Other Button", nil];
    [alertView show];
}



- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        NSLog(@"User Selected Cancel");
    }
    else if (buttonIndex == 1) {
        NSLog(@"Modal Button Clicked");
        aNavController.modalPresentationStyle = UIModalPresentationFormSheet;
        anavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [self presentModalViewController:aNavController animated:YES];
        aNavController.view.superview.frame = CGRectMake(40,50, 400, 500);
    }else {
        NSLog(@"Some Other Button Clicked");
    }
}

或者,如果您希望UIAlertView显示在导航控制器的顶部,请忽略上述内容,只需等待导航控制器- (void)viewDidAppear:(BOOL)animated方法调用警报。

此外,除非绝对必要,否则我建议您更改框架以保持在屏幕范围内。例如:CGRectMake(40, 50, 320, 480);

答案 2 :(得分:0)

最后,我能够解决与UIModalPresentationFormSheet相同的工作方式。

我将aNavController作为子视图添加到[[UIApplication sharedApplication] keyWindow]中,这解决了我的所有问题。

谢谢大家的意见。