Pergunta

I've been trying to create a UIStoryboardSegue that mimics the "Cover Vertical" modal segue, but makes the view "Uncover," so that the segues look natural together. Here's my UIStoryboardSegue child class:

//RetreatVertical.m

#import "RetreatVertical.h"
@implementation RetreatVertical

-(void)perform {
    UIView *oldView = [self.sourceViewController view];
    UIView *newView = [self.destinationViewController view];
    [oldView.window insertSubview:newView belowSubview:oldView];

    [UIView animateWithDuration:0.3 animations:^{
        oldView.center = CGPointMake(oldView.center.x, oldView.center.y + oldView.frame.size.height); }
        completion:^(BOOL finished){ [oldView removeFromSuperview]; }
     ];
}

@end

When the user taps a button, a UIViewController slides into focus using the modal segue "Cover Vertical." When the user taps a button on the new UIViewController, that UIViewController slides back down, revealing the old UIViewController (using my custom segue "RetreatVertical"). That all works fine, however, whenever I tap any other button or interface element after both animations are completed, the app crashes with "EXC_BAD_ACCESS." I have no idea why, and the past hour of searching hasn't come up with anything.

Thanks!

EDIT: Why doesn't this strategy work?

- (void) perform {
    UIView *sourceView = [self.sourceViewController view];
    UIView *destView = [self.destinationViewController view];
    [[self.sourceViewController superview] insertSubview:destView belowSubview:sourceView];

    [UIView animateWithDuration:0.3 animations:^{
        sourceView.center = CGPointMake(sourceView.center.x, sourceView.center.y + sourceView.frame.size.height); }
        completion:^(BOOL finished){ [sourceView removeFromSuperview]; }
     ];
}
Foi útil?

Solução

Messing around with the Application Window directly (and it's subviews) is always tricky and extremely hard to get right; there's a lot of hidden stuff going on that you can't possibly account for. So lets just change your hierarchy slightly to make everything easier.

Right now you have:

A = Root VC

B = New VC

Transition: Window { A -----> B }

Better solution:

A = Root VC

B = New VC

C = Old VC

Transition: Window { A { C -----> B } }

Meaning that have your Root just be a plain VC with a blank view that you push your views on top of. This will allow you to easily do whatever animations you wish without having to worry about screwing up your main window.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top