How to encode a user segment that “slides” between view managers?

I built a storyboard application, with an initial view controller, connected to many subsequent view controllers, sequentially using cross-dissolving segue. These works work. Everything is working fine. However, instead of having to use the main segments, I want to have a custom segment that will move the contents of the view controller on and off the screen, similar to clicking on navigationControllers, but when turned on left and right depending on one goes forward or backward in the application.

I set segue to custom, and created and saved the MySegue.h file. HOWEVER, I don’t know how to encode a user segment that will shift one view manager from the screen while the other slides on and back and forth when I switch between view controllers.

Can someone please give me the encoding (it should be easy!) For custom segue to go from one view controller to the next and back by moving the screen left and left, so I don't need to use basic cross-dissolution or standard flips offered in Xcode 4.2? I would be very grateful.

+6
source share
3 answers

I ran into the same problem, but I used gesture wipes to move from one controller to another. Using the storyboard itself to configure segues worked fine, but when I needed to “go back” to the previous view controller, the animation moved from right to left, and not from left to right. To fix this problem, I did the following:

  • Built-in navigation controller in root view.
  • Used by segues to launch new view controllers.
  • When I wanted to "go back" to the previous view controller, I did not add segue to the storyboard to push the previous view controller. Instead, I called the navigation controller popViewControllerAnimated whenever a reverse popViewControllerAnimated occurred.
+4
source

To create a custom segment that the view slide controllers first create a class that extends the UIStoryboardSegue, then override the execution selector. I just did something like this and it will work for you too. Here is my code:

 #define kAnimationDuration 0.5 #import "CustomSlideSegue.h" @implementation CustomSlideSegue - (void)perform { UIViewController *sourceViewController = (UIViewController *) self.sourceViewController; UIViewController *destinationViewController = (UIViewController *) self.destinationViewController; [sourceViewController.view addSubview:destinationViewController.view]; [destinationViewController.view setFrame:sourceViewController.view.window.frame]; [destinationViewController.view setBounds:sourceViewController.view.bounds]; CGSize screenSize = [[UIScreen mainScreen] bounds].size; if ( !self.slideLeft ) { [UIView animateWithDuration:kAnimationDuration delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{ [destinationViewController.view setCenter:CGPointMake(screenSize.height + screenSize.height/2, screenSize.height/2 - 138)]; [destinationViewController.view setCenter:CGPointMake(screenSize.width/2 + 127, screenSize.height/2 - 138)]; } completion:^(BOOL finished){ [destinationViewController.view removeFromSuperview]; [sourceViewController presentViewController:destinationViewController animated:NO completion:nil]; }]; } else { [UIView animateWithDuration:kAnimationDuration delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{ [destinationViewController.view setCenter:CGPointMake(-1*screenSize.height/2, screenSize.height/2 - 138)]; [destinationViewController.view setCenter:CGPointMake(screenSize.width/2 + 127, screenSize.height/2 - 138)]; } completion:^(BOOL finished){ [destinationViewController.view removeFromSuperview]; [sourceViewController presentViewController:destinationViewController animated:NO completion:nil]; }]; } } 

Then, when you want to execute segue, use this code:

  UIViewController *destination = [self.storyboard instantiateViewControllerWithIdentifier:@"some identifier"]; CustomZoomSegue *segue = [[CustomZoomSegue alloc] initWithIdentifier:@"segue vc identifier" source:self destination:destination]; [self prepareForSegue:segue sender:self]; [segue perform]; 

CGPointMake calls are common to my code (I used landscape orientation), but you should be able to change it to suit your needs. If you need to clarify or ask a question, let me know and I will try to answer.

NOTE. I use storyboards without segue lines between view controllers.

+2
source

Why not just use the UINavigationController ? This seems to be exactly what they are for.

0
source

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


All Articles