8

一段时间以来,我一直在尝试创建与垂直封面相反的自定义 segue(创建从上到下的效果动画)。我查看了其他问题,google 和 youtube,但无法使其正常工作。我是对课程等都是全新的,因此分步指南或视频中的任何帮助都会非常好。我相信这个 URL 正在尝试做一些类似于我想要的事情:

http://jrwren.wrenfam.com/blog/2012/02/01/storyboard-custom-segue-for-custom-pushviewcontroller-animation/,我就是无法让它工作。

如果你们中的任何人都知道一种方法来创建一个从上到下版本的封面垂直转场,你能帮我吗?

4

7 回答 7

8

好吧,您会想要创建 UIStoryBoardSegue 的子类,就像演练向您展示的那样,但是在 Storyboard 类的 .m 文件(实现)下,您需要以下代码作为您的 -(void)perform:方法 -

-(void)perform{
UIViewController *sourceViewController = (UIViewController *) self.sourceViewController;
UIViewController *destinationViewController = (UIViewController *) self.destinationViewController;
[sourceViewController.view addSubview:destinationViewController.view];
[destinationViewController.view setFrame:sourceViewController.view.window.frame];
[destinationViewController.view setTransform:CGAffineTransformMakeTranslation(0, -sourceViewController.view.frame.size.height)];
[destinationViewController.view setAlpha:1.0];

[UIView animateWithDuration:0.75
                      delay:0.0
                    options:UIViewAnimationOptionTransitionFlipFromTop
                 animations:^{
                     [destinationViewController.view setTransform:CGAffineTransformMakeTranslation(0, 0)];
                     [destinationViewController.view setAlpha:1.0];
                 }
                 completion:^(BOOL finished){
                     [destinationViewController.view removeFromSuperview];
                     [sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
                 }];}

希望这会有所帮助。

于 2012-12-29T13:45:14.233 回答
3

以@dmason82 的回答为基础,翻译成 Swift,并稍微简化一下,这对我有用:

class UIStoryboardSegueFromTop: UIStoryboardSegue {
    override func perform() {
        let src = self.sourceViewController as UIViewController
        let dst = self.destinationViewController as UIViewController

        src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
        dst.view.transform = CGAffineTransformMakeTranslation(0, -src.view.frame.size.height)

        UIView.animateWithDuration(1.0, animations: {
            dst.view.transform = CGAffineTransformMakeTranslation(0, 0)

            }) { (Finished) in
                src.presentViewController(dst, animated: false, completion: nil)
        }
    }
}
于 2016-04-22T17:16:02.463 回答
2

这是我使用情节提要实现对面封面垂直转场

https://github.com/viccarre/OppositeCoverVerticalSegue

于 2014-07-12T21:36:58.497 回答
1

嗨,我刚刚尝试了另外两个答案,但它没有按您的要求工作。为了创建一个自定义的segue,看起来与cover vertical(模态segue默认)完全相反,我创建了这个代码:

- (void)perform
{
UIViewController *sourceViewController = self.sourceViewController;
UIViewController *destinationViewController = self.destinationViewController;


[sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
[destinationViewController.view addSubview:sourceViewController.view];
[sourceViewController.view setTransform:CGAffineTransformMakeTranslation(0, 0)];
[sourceViewController.view setAlpha:1.0];

[UIView animateWithDuration:0.75
                      delay:0.0
                    options:UIViewAnimationOptionTransitionFlipFromBottom
                 animations:^{
                     [sourceViewController.view setTransform:CGAffineTransformMakeTranslation(0,destinationViewController.view.frame.size.height)];
                     [sourceViewController.view setAlpha:1.0];
                 }
                 completion:^(BOOL finished){
                     [sourceViewController.view removeFromSuperview];
                     }];

}


@end
于 2014-05-18T17:15:13.030 回答
1

要完成 dmason 的回答并让您的控制器朝相反的方向展开 - 从它来的地方返回,请在呈现的视图控制器中执行此操作:

[UIView animateWithDuration:0.75
                      delay:0.0
                    options:UIViewAnimationOptionTransitionFlipFromBottom
                 animations:^{
                     [self.view setTransform:CGAffineTransformMakeTranslation(0, -self.view.frame.size.height)];
                 }
                 completion:^(BOOL finished){
                     [self dismissViewControllerAnimated:NO completion:nil];
                 }
 ];

伯格的回答对我不起作用。

于 2015-11-19T16:13:27.807 回答
0

dmason 的回答很棒,如果您想添加一个展开转场,以便您的模态在关闭时正确动画,您的执行操作可能看起来像这样(在新的自定义转场类中)

- (void)perform
{
    UIViewController *sourceViewController = self.sourceViewController;
    UIViewController *destinationViewController = self.destinationViewController;

    [sourceViewController dismissViewControllerAnimated:NO completion:nil];
    [destinationViewController.view addSubview:sourceViewController.view];

    [UIView animateWithDuration:0.75
                     animations:^{
                         sourceViewController.view.center = CGPointMake(sourceViewController.view.center.x, sourceViewController.view.center.y-600);
                     }
                     completion:^(BOOL finished){
                         [sourceViewController.view removeFromSuperview];
                     }
     ];
}
于 2014-04-23T18:23:51.843 回答
0

我建议你使用 Hero 库来实现这一点。它添加了很多动画和过渡,特别是在视图控制器之间:https ://github.com/lkzhao/Hero/blob/master/README.md 有一个过渡叫做“Cover”,你可以选择方向(左, 上, 右, 下)

于 2017-09-11T19:47:38.220 回答