How to make popup / dialog presentation in iOS in a separate ViewController?

I am making an iOS game and I want to achieve this effect: pause popup 2 different controllers

I know how to do this using one view controller, but the view controller class has already been swollen with code, and the storyboard of this screen is a mess (I actually have many other views that above, I just hid them for clarity of reason).

So my questions are: is there a way to achieve this using a separate view controller to control this pause? I need a segue that will not miss the previous screen presented. I want to do this with a storyboard. I tried the "popover" segue, but appeared with a strange border that I don't want.

, , , . , , BG . ?

.

+5
4

, .

1 - PauseViewController . , , Alpha 0 , . .h .m

2 - (UIButtons). , . , .

- (IBAction)dismiss:(id)sender {
    [UIView animateWithDuration:0.3f animations:^{
        self.view.alpha = 0.0f;
    } completion:^(BOOL finished) {
        [self.view removeFromSuperview];
        [self removeFromParentViewController];
    }];
}

3 - UIStoryboardSegue, segue. - . ( ) .

-(void)perform{
    UIViewController *dst = [self destinationViewController];
    UIViewController *src = [self sourceViewController];

    // add the view to the hierarchy and bring to front
    [src addChildViewController:dst];
    [src.view addSubview:dst.view];
    [src.view bringSubviewToFront:dst.view];

    // set the view frame
    CGRect frame;
    frame.size.height = src.view.frame.size.height;
    frame.size.width = src.view.frame.size.width;
    frame.origin.x = src.view.bounds.origin.x;
    frame.origin.y = src.view.bounds.origin.y;
    dst.view.frame = frame;

    [UIView animateWithDuration:0.3f animations:^{ 
        dst.view.alpha = 0.5f;
    }];
}

4 - segue, custom segue.

Ta-!

, .

+16

childViewControllers. , - .

PauseMenuViewController *pauseMenuVC = [[PauseMenuViewController alloc] init]; 
[self addChildViewController:pauseMenuVC];
if ([self isViewLoaded]){
    [self.view addSubview:pauseMenuVC.view];
}

, , .

Apple Docs

+2

, cocos 2d. iOS .

  • ( UIlabel).
  • . . .
  • / .

, . , , .

0
source

As an answer option related to the UIStoryboardSegue subclass, you can also use the 1x1 transparent image "blank.png". This way, you only need to do the alpha of the supervisory of the pop-up controller so that the pop-up in the middle can have full visibility if necessary.

    -(void)perform
    {
        UIViewController *dst = [self destinationViewController];
        UIViewController *src = [self sourceViewController];

        // add the view to the hierarchy and bring to front
        [src addChildViewController:dst];
        [src.view addSubview:dst.view];
        [src.view bringSubviewToFront:dst.view];

        // set the view frame
        CGRect frame;
        frame.size.height = src.view.frame.size.height;
        frame.size.width = src.view.frame.size.width;
        frame.origin.x = src.view.bounds.origin.x;
        frame.origin.y = src.view.bounds.origin.y;
        dst.view.frame = frame;
        dst.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"blank.png"]];

        [UIView animateWithDuration:0.3f animations:^{
            dst.view.alpha = 1;
        }];
    }
0
source

All Articles