UIViewController半屏“抽屉滑动”animation

我想有一个UIViewController出现在右边的“幻灯片”animation。 不像一个推塞格,不喜欢Facebook的应用程序。 我想要新的ViewController滑动当前的TOP(不推)它,但只覆盖屏幕的一部分,而其他部分显示第一个ViewController。

我所尝试过的:我所得到的最接近的是通过创build一个自定义的segue与以下内容:

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

这实现了我所要做的animation,但它覆盖了整个第一个ViewController。 我如何让它在某个时候停下来,而不是覆盖整个事物呢?

我正在使用故事板,这是我第一次尝试任何一种新的animation。

你可以尝试在你的源代码视图控制器中做,并改变你的目的地(x轴)的框架,如:

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

这应该做到这一点!

让我知道如果没有…

UPDATE !:

@CaptJak嘿,对不起,没有为你工作..我写了下面的代码,它的工作没有任何问题在这里..我把它链接到一个button单击..试试看,让我知道! (PS:我也添加了animation!)。

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

使用Albara给出的答案,我也可以用相同的animation创build一个segue。 自定义segue如下所示:

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

只是一个重命名的问题,真的。

我只是创buildNDOverlayViewController来做这样的事情。 实际上,它可以覆盖/滑动一个视图控制器从任何边缘的可变偏移量,范围和animation选项。 我创造了它作为一个实验,但也许这将有助于某人?