UIViewController半屏“抽屉幻灯片"动画片 [英] UIViewController half screen "drawer slide" animation

查看:132
本文介绍了UIViewController半屏“抽屉幻灯片"动画片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示一个UIViewController,并在右侧显示一个幻灯片"动画.不像Push segue,也不像Facebook应用程序.我希望新的ViewController在当前控件的顶部上滑动(而不是将其推开),而只覆盖屏幕的一部分,而另一部分显示第一个ViewController.

I am trying to have a UIViewController that appears with a "slide" animation from the right. Not like a Push segue, not like the Facebook app. I want the new ViewController to slide ON TOP of the current one (not push it away), but only cover PART of the screen, leaving the other part showing the first ViewController.

我尝试过的事情:我得到的最接近的结果是通过创建具有以下内容的自定义序列:

What I have tried: The closest that I have gotten is by creating a custom segue 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];
}

这实现了我想要的动画,但是它覆盖了整个第一个ViewController.我将如何使它停在某个点上而不覆盖全部内容?

This achieves the animation that I am going for, but it covers the entire first ViewController. How would I make it stop at a certain point and not cover the entire thing?

我正在使用情节提要,这是我第一次尝试任何新动画.

I am using Storyboards, and I this is my first time trying any sort of new animation.

推荐答案

您可以尝试在源视图控制器中执行此操作,并为目标(x轴)更改框架,例如:

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]; 
}

那应该做到!

让我知道是否不是...

Let me know if it didn't...

更新!:

@CaptJak嘿,对不起,这对您不起作用..我编写了以下代码,并且在这里没有任何问题..我将其链接到单击按钮..尝试一下,让我知道! (PS:我也添加了动画!).

@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)];
}];

这篇关于UIViewController半屏“抽屉幻灯片"动画片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆