简体   繁体   English

将Push ViewController动画更改为看起来像“ pop”动画,从左到右

[英]Changing Push ViewController animation to look like a “pop” animation, come in from left to right

Right now I am using a segue from storyboard to push a view controller and there is just the one push transition. 现在,我正在使用情节提要中的segue来推送视图控制器,并且只有一个推送过渡。 How can I imitate the "Pop" transition in code? 如何在代码中模仿“ Pop”过渡? Can I do this while still using storyboard for my other transitions in place now? 我可以在仍使用情节提要板进行其他过渡的同时执行此操作吗?

UPDATE 更新

I tried what is suggested in the first comment here, with some changes. 我尝试了此处第一条评论中的建议,并进行了一些更改。 Here's what I have: 这是我所拥有的:

UIViewController *dst = [self destinationViewController];
UIViewController *src = [self sourceViewController];
[dst viewWillAppear:YES];
[dst viewDidAppear:NO];

CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGRect f = CGRectMake(-screenBounds.size.width, 0, screenBounds.size.width, screenBounds.size.height);
dst.view.frame = f;
f.origin.x = screenBounds.size.width;
src.view.frame = f;

[UIView transitionFromView:src.view
                    toView:dst.view
                  duration:0.3
                   options:UIViewAnimationOptionTransitionNone
                completion:^(BOOL finished){
     [dst viewDidAppear:YES];

     UINavigationController *nav = src.navigationController;
     [nav popViewControllerAnimated:NO];
     [nav pushViewController:dst animated:NO];
 }];

This is working almost how I want, but the original viewcontroller is just disappearing instead of sliding to the right. 这几乎可以按照我想要的方式工作,但是原始的viewcontroller只是消失了而不是向右滑动。

You can create Segue type "Custom" on your stroyboard and create a new UIStoryboardSegue class named "popSegue" In the popSegue.m file add this: 您可以在滑板上创建Segue类型“ Custom”,并创建一个名为“ popSegue”的新UIStoryboardSegue类。在popSegue.m文件中添加以下内容:

    -(void)perform{
UIViewController *sourceViewContreoller = [self sourceViewController];

CATransition *animation = [CATransition animation];
[animation setType:kCATransitionFromLeft]; //or kCATransitionFromRight 
[animation setDuration:0.25];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                              kCAMediaTimingFunctionEaseIn]];

[sourceViewContreoller.navigationController.view.layer addAnimation:animation forKey:@"animateOpacity"]; //or key=@"fadeTransition"

[sourceViewContreoller.navigationController popViewControllerAnimated:YES];

[CATransaction commit];
}

In the storyboard editor Select the segue and change the Segue Class to "popSegue". 在情节提要板编辑器中,选择segue,并将Segue类更改为“ popSegue”。 Set the Identifier to "popSegue". 将标识符设置为“ popSegue”。 Try this and comment for your result 试试这个,并为您的结果发表评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM