代码之家  ›  专栏  ›  技术社区  ›  Julian Coltea

可编程推送模式视图控制器[副本]

  •  1
  • Julian Coltea  · 技术社区  · 14 年前

    可能重复:
    How to create custom modal segue in 4.2 Xcode using storyboard

    所以我有一个视图控制器,我想把它模式化地推到我当前的视图控制器上。这是我的故事板的屏幕截图,我试图加载的视图突出显示: enter image description here

    因此,我在当前视图和第二个导航控制器之间创建了一个分段,称之为“alert”。因为我没有将segue绑定到任何类型的按钮,所以我只是试图在以下if语句中以模式加载视图:

    if([detector judgeSpeed:[ratio floatValue]])
    {
        //push the new view here
    }
    

    我该怎么做?我需要实现某种委托或prepareForSegue方法吗?

    4 回复  |  直到 7 年前
        1
  •  5
  •   Community Mohan Dere    9 年前

    你可以使用segue,但这里有另一种选择:

    SomeViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"SomeIdentifier"];
    [self.navigationController presentModalViewController:controller animated:YES]
    

    请记住在情节提要中设置视图控制器的标识符。

    更多信息和示例项目 here 。

        2
  •  3
  •   Simon    10 年前

    呈现模式视图控制器 是iOS 6的代码,但我需要iOS 9的代码。有人能帮忙吗?

        3
  •  1
  •   Community Mohan Dere    9 年前

    答案已打开 How to create custom modal segue in 4.2 Xcode using storyboard 应该会有所帮助。

    T.J 的答案:

    UIViewController *src = (UIViewController *) self.sourceViewController;
    [UIView transitionWithView:src.navigationController.view duration:0.5
                       options:UIViewAnimationOptionTransitionFlipFromTop
                    animations:^{
                        [src.navigationController popToViewController:[src.navigationController.viewControllers objectAtIndex:0] animated:NO];;
                    }
                    completion:NULL];
    

    tiguero 的答案:

    [self.sourceViewController presentModalViewController:self.destinationViewController animated:NO];
    

    这些答案中的任何一个都应该回答这个问题。

        4
  •  0
  •   user1349234 user1349234    14 年前

    在情节提要中,通过从视图控制器本身ctrl拖动到新的视图控制器,创建一个从演示视频捕获视图控制器到新视图控制器的片段。您可以通过ctrl从Demo Video Capture View Controller下方黑色条中的黄色按钮拖动到新视图来完成此操作。当它询问选择哪种时 modal 。仍然在情节提要中,单击segue并在右侧的身份导航器中将其标识为“alert”。现在转到.m文件并使用此实现。。。

    if([detector judgeSpeed:[ratio floatValue]])
    {
       [self performSegueWithIdentifier:@"alert" sender:self];
    }