Xcode自定义segue动画

Jon*_*ter 2 xcode animation storyboard segue uistoryboardsegue

我有两个故事板控制器之间的过渡动​​画的问题.我在storyboard中有一个带有两个视图控制器的singleView项目.

现在我想制作一个自定义过渡动画:

  • 我当前的视图控制器应该消失在左边
  • 新视图控制器应该来自右侧

我已经UIStoryboardSegue上课了.

但是我应该在-(void)perform{}方法中写什么?

非常感谢,

乔纳斯.

Odr*_*kir 11

对于那个简单的segue,您可以尝试这样的事情:

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

    CGRect sourceFrame = source.view.frame;
    sourceFrame.origin.x = -sourceFrame.size.width;

    CGRect destFrame = destination.view.frame;
    destFrame.origin.x = destination.view.frame.size.width;
    destination.view.frame = destFrame;

    destFrame.origin.x = 0;

    [source.view.superview addSubview:destination.view];

    [UIView animateWithDuration:1.0
                     animations:^{
                         source.view.frame = sourceFrame;
                         destination.view.frame = destFrame;
                     }
                     completion:^(BOOL finished) {
                         UIWindow *window = source.view.window;
                         [window setRootViewController:destination];
                     }];
}
Run Code Online (Sandbox Code Playgroud)