Question

I'm trying to implement an iBooks-like flip transition as a storyboard. The segue should push resp. pop the destinationViewController onto/from the UINavigationControllers stack.

I can push viewcontrollers in my segues perform method but I am not able to pop. When I pop the controller right after creating my flip animation the animation does not run and its callback - that should perform [[UIApplication sharedApplication] endIgnoringInteractionEvents] gets never called and my App results dead.

So I tried to push/pop in the animationDidStop:anim:flag delegate method but it never gets called with the flag set to true.

I assume that the segue is deallocated before the delegate method gets called. What else could I do?

Was it helpful?

Solution

Forgive me if I am completely misunderstanding this question, but it seems like you just want to do a basic horizontal flip back and forth between two view controllers. And even if you've already figured this out, maybe it will help anyone else who has the same question.

(1) In your storyboard (that has ViewController A & B) create a Modal Segue from A to B. Give it an identifier (showViewControllerB) and choose Transition:Flip Horizontal.

We set up the protocol and delegates:

(2a) In ViewControllerB.h add above @interface:

@class ViewControllerB;

@protocol ViewControllerBDelegate
    - (void)viewControllerBDidFinish:(ViewControllerB *)controller;
@end

(2b) Add the delegate as a property:

@property (weak, nonatomic) id <ViewControllerBDelegate> delegate;

(3a) In ViewControllerB.m synthesize:

@synthesize delegate;

(3b) And delegate in the method to flip back:

- (IBAction)flipBack:(id)sender
{
    [self.delegate viewControllerBDidFinish:self];
}

(4) In ViewControllerA.h add at the very top #import "ViewControllerB.h" and on the end of @interface <ViewControllerBDelegate>

(5a) In ViewControllerA.m add the method to conform to the protocol:

- (void)viewControllerBDidFinish:(ViewControllerB *)controller
{
    [self dismissModalViewControllerAnimated:YES];
}

(5b) Then set it as the delegate in prepareForSegue:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showViewControllerB"]) {
        [[segue destinationViewController] setDelegate:self];
    }
}

I hope this answers your question. If I misunderstood, just let me know.

OTHER TIPS

Your question is a bit confusing as so mingle pop, push, flip and backflip. I´m not sure if ai can answer your question, but i can tell what i did.

If i push a viewController into the navigation controller stack and set the Storyboard Segue Style to Push, it will be pushed into the view from right to left. A back button appears and shows the title of the presentingViewController in it.

If i set the Storyboard Segue Style to Modal i can set the Transition to Flip Horizontal (what seems to be what you want). But then no Back Button will appear. In the presentedViewController i dismiss the view with:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

It will flip the second view back with a right flip.

But this is the dirty solution and it is not recommended by apple.

http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ManagingDataFlowBetweenViewControllers/ManagingDataFlowBetweenViewControllers.html#//apple_ref/doc/uid/TP40007457-CH8-SW9

Luke Dubert gave you an example how to implement the delegate.

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