Xcode custom segue animation

纵然是瞬间 提交于 2019-12-05 05:00:53

问题


I have a problem with the transition animation between two storyboard controllers. I have a singleView project with two view controllers in the storyboard.

Now I wand to make a custom transition animation:

  • my current view controller should disappear to the left
  • the new view controller should come from the right

I have already a UIStoryboardSegue class.

But what should I write in the -(void)perform{} method??

Thanks a lot,

Jonas.


回答1:


For that simple segue you can try something like this:

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


来源:https://stackoverflow.com/questions/19243131/xcode-custom-segue-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!