UIViewController half-screen drawer slide

I am trying to have a UIViewController that appears with a slide animation on the right. Not like Push Segue, not a Facebook app. I want the new ViewController to move to the top of the current (without pushing it away), but only close the PART of the screen, leaving the other part showing the first ViewController.

What I tried: The closest I got is creating a custom segment with the following:

 - (void)perform { __block UIViewController *src = (UIViewController *) self.sourceViewController; __block UIViewController *dst = (UIViewController *) self.destinationViewController; CATransition* transition = [CATransition animation]; transition.duration = .50; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; transition.type = kCATransitionMoveIn; transition.subtype = kCATransitionFromRight; [src.navigationController.view.layer addAnimation:transition forKey:@"SwitchToView1"]; [src.navigationController pushViewController:dst animated:NO]; } 

This provides the animation I'm going to, but it covers the entire first ViewController. How can I stop it at a certain moment and not cover it all?

I use storyboards, and this is the first time I'm using a new animation.

+8
ios uiviewcontroller storyboard segue uiviewanimation
source share
3 answers

You can try to do this in your source code view controller and change the frame for your destruction (x axis) like this:

 - (void) perform { UIViewController *dst = (UIViewController *) self.destinationViewController; [dst.view setFrame:CGRectMake(160, 0, YOUR_DST_WIDTH, YOUR_DST_HEIGHT)]; //your animation stuff... [self addChildViewController:dst]; [self.view addSubview:dst.view]; [dst didMoveToParentViewController:self]; } 

And it must be!

Let me know if this is not ...

UPDATE:

@CaptJak Hey, sorry this didn't work for you. I wrote the following code and it works without problems here. I linked it to the button by clicking .. try and let me know! (PS: I added animation too!).

 ViewController *tlc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainViewController"]; [tlc.view setFrame:CGRectMake(-320, 0, self.view.frame.size.width, self.view.frame.size.height)]; [self addChildViewController:tlc]; [self.view addSubview:tlc.view]; [tlc didMoveToParentViewController:self]; [UIView animateWithDuration:0.3 animations:^{ [tlc.view setFrame:CGRectMake(-160, 0, self.view.frame.size.width, self.view.frame.size.height)]; }]; 
+12
source share

Using the answer given by Albara, I was also able to create a shogu with the same animation. The user segment is as follows:

 - (void)perform { UIViewController *src = (UIViewController *)self.sourceViewController; UIViewController *dst = (UIViewController *)self.destinationViewController; [dst.view setFrame:CGRectMake(380, 0, dst.view.frame.size.width, dst.view.frame.size.height)]; [src addChildViewController:dst]; [src.view addSubview:dst.view]; [dst didMoveToParentViewController:src]; [UIView animateWithDuration:0.5 animations:^{ [dst.view setFrame:CGRectMake(300, 0, src.view.frame.size.width, src.view.frame.size.height)]; }]; } 

Just a rename, really.

+5
source share

I just created an NDOverlayViewController to do something like this. In fact, it can superimpose / shift one view controller over another from any edge with parameters for displacement, extent and animation. I created it as an experiment, but maybe it will be useful to someone?

+2
source share

All Articles