Custom Segue Pushing / Popping UIViewControllers

I am trying to implement the transition to iBooks-flip as a storyboard. Seg should move accordingly. enter destinationViewController to / from the UINavigationControllers stack.

I can click viewcontrollers in my segues perform method, but I cannot pop. When I go to the controller immediately after creating the flip animation, the animation does not start, and its callback [[UIApplication sharedApplication] endIgnoringInteractionEvents] is never called, and the results of my application are dead.

So, I tried to push / change the delegate method animationDidStop:anim:flag , but it is never called with the flag set to true.

I assume that segue is freed before calling the delegate method. What else could I do?

+6
source share
2 answers

Forgive me if I completely misunderstand this question, but it looks like you just want to make a basic horizontal click back and forth between two view controllers. And even if you already understood this, perhaps this will help anyone who has the same question.

(1) In your storyboard (with ViewController A and B), create a Modal Segue from A to B. Give it an identifier (showViewControllerB) and select Transition: Flip Horizontal.

We installed the protocol and the delegates:

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

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

(2b) Add a delegate as a property:

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

(3a) In ViewControllerB.m, it synthesizes:

 @synthesize delegate; 

(3b) And the delegate in the method for returning:

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

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

(5a) In ViewControllerA.m, add a method to comply with the protocol:

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

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

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

Hope this answers your question. If I do not understand, just let me know.

+5
source

Your question is a bit confusing, so mix pop, press, sit back and lean back. I'm not sure if ai can answer your question, but I can say what I did.

If I push viewController onto the navigator controller stack and set the Segue Storyboard Push style, it will be moved to the view from right to left. The back button opens and displays the title of the presented ViewController.

If I set the Storyboard Segue style to Modal, I can set the transition to Flip Horizontal (which seems to be what you want). But then the back button will not appear. In the presented ViewController, I reject the view with:

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

It will flip the second view back using the right flip.

But this is a dirty solution, and it is not recommended by an 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 of how to implement a delegate.

0
source

Source: https://habr.com/ru/post/906895/


All Articles