Question

I have two View Controllers with views. The first one is a login screen and the second one fetches stuff from the web (irrelevant).

I used a custom segue animation and had to do some weird stuff with the superview to get the sourceViewController.view to be "on top" (visually) of the destinationViewController.view

I can only assume this is why when i try to call IBAction methods from the second view they won't call.

Here is the segue class implementation:

- (void) perform {

    UIViewController *sourceViewController = (UIViewController *) self.sourceViewController;
    UIViewController *destinationViewController = (UIViewController *) self.destinationViewController;

    UIView *parent = sourceViewController.view.superview;
    [sourceViewController.view removeFromSuperview];
    [parent addSubview: destinationViewController.view];
    [parent addSubview:sourceViewController.view];
    sourceViewController.view.layer.masksToBounds = NO;
    sourceViewController.view.layer.cornerRadius = 8; // if you like rounded corners
    sourceViewController.view.layer.shadowOffset = CGSizeMake(0,0);
    sourceViewController.view.layer.shadowRadius = 10;
    sourceViewController.view.layer.shadowOpacity = 1;

    destinationViewController.view.frame = CGRectMake(0, 20, destinationViewController.view.frame.size.width, destinationViewController.view.frame.size.height);
    sourceViewController.view.frame = CGRectMake(0, 20, sourceViewController.view.frame.size.width, sourceViewController.view.frame.size.height);

    [UIView animateWithDuration:.6
                          delay:0.0
                        options:UIViewAnimationCurveEaseInOut
                     animations:^{

                         sourceViewController.view.frame = CGRectMake(-sourceViewController.view.frame.size.width-10, 20, sourceViewController.view.frame.size.width, sourceViewController.view.frame.size.height);
                     }
                     completion:^(BOOL finished){
                         //[destinationViewController.view removeFromSuperview];
                         [sourceViewController.navigationController pushViewController:destinationViewController animated:NO];
                     }];
}

My question is, can removing the source view from its superview and playing around with that ruin the way that IBActions are called on the second view?

The IBAction methods just crash the app, on a button push for example.

Was it helpful?

Solution

I fixed my issue by changing my code to this:

UIViewController *sourceViewController = (UIViewController *) self.sourceViewController;
    UIViewController *destinationViewController = (UIViewController *) self.destinationViewController;
UIView *parent = sourceViewController.view.superview;
[parent addSubview:destinationViewController.view];
[parent sendSubviewToBack: destinationViewController.view];
    sourceViewController.view.layer.masksToBounds = NO;
    sourceViewController.view.layer.cornerRadius = 8; // if you like rounded corners
    sourceViewController.view.layer.shadowOffset = CGSizeMake(0,0);
    sourceViewController.view.layer.shadowRadius = 10;
    sourceViewController.view.layer.shadowOpacity = 1;
destinationViewController.view.frame = CGRectMake(0, 20, destinationViewController.view.frame.size.width, destinationViewController.view.frame.size.height);
    sourceViewController.view.frame = CGRectMake(0, 20, sourceViewController.view.frame.size.width, sourceViewController.view.frame.size.height);

    [UIView animateWithDuration:.6
                          delay:0.0
                        options:UIViewAnimationCurveEaseInOut
                     animations:^{

                         sourceViewController.view.frame = CGRectMake(-sourceViewController.view.frame.size.width-10, 20, sourceViewController.view.frame.size.width, sourceViewController.view.frame.size.height);
                     }
                     completion:^(BOOL finished){
                         [sourceViewController presentViewController:destinationViewController animated:NO completion:NULL];
                     }];

A few things changed, but notably, i used

[sourceViewController presentViewController:destinationViewController animated:NO completion:NULL];

to initialise the controller properly. Hope this helps someone else out in the future.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top