UIViewController半屏"抽屉幻灯片"动画

Cap*_*Jak 8 storyboard uiviewcontroller uiviewanimation ios segue

我试图让UIViewController右边的"幻灯片"动画出现.不像Push segue,不像Facebook应用程序.我希望新的ViewController在当前的一个上滑动(不要将它推开),但只覆盖屏幕的PART,而另一部分则显示第一个ViewController.

我尝试过的:我得到的最接近的是创建一个具有以下内容的自定义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];
}
Run Code Online (Sandbox Code Playgroud)

这实现了我想要的动画,但它涵盖了整个第一个ViewController.我怎么能让它停在某一点而不是覆盖整个事物?

我正在使用Storyboards,这是我第一次尝试任何类型的新动画.

Alb*_*ara 12

您可以尝试在源视图控制器中执行此操作,并更改destnation(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]; 
}
Run Code Online (Sandbox Code Playgroud)

这应该做到!

如果没有,请告诉我......

UPDATE !:

@CaptJak嘿,很抱歉没有为你工作..我写了下面的代码,它在这里工作没有任何问题..我把它链接到一个按钮点击..尝试它让我知道!(PS:我也添加了动画!).

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)];
}];
Run Code Online (Sandbox Code Playgroud)


Cap*_*Jak 5

使用Albara给出的答案,我还能够创建一个具有相同动画的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)];
    }];

}
Run Code Online (Sandbox Code Playgroud)

只是重命名,真的.