UIViewController half screen “drawer slide” animation

馋奶兔 提交于 2019-12-03 12:57:18
Albara

You can try doing it in your source view controller, and changing the frame for your destnation (the x axis) something like:

- (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 that should do it!

Let me know if it didn't...

UPDATE!:

@CaptJak Hey, sorry that didn't work out for you.. I wrote the following code, and it works without any problems here.. I linked it to a button click.. try it and let me know! (PS: I added animations 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)];
}];

Using the answer given by Albara, I was able to also create a segue with the same animation. The custom segue 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 matter of renaming, really.

I just created NDOverlayViewController to do something like this. Actually it can overlay/slide one view controller over another from any edge with variable offset, extent and animation options. I created it as an experiment but maybe it will be helpful to somebody?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!