【问题标题】:Xcode custom segue animationXcode 自定义 segue 动画
【发布时间】:2013-10-15 02:32:56
【问题描述】:

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

现在我想做一个自定义的过渡动画:

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

我已经有一个UIStoryboardSegue 类。

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

非常感谢,

乔纳斯。

【问题讨论】:

  • 只要在google上写“custom segue”,你就会发现很多例子。首先做一些尝试,然后带着你尝试过的东西来到这里。一个例子:blog.jimjh.com/…
  • 顺便说一句,您想要的动画是默认的 push segue 动画,您不必为此编写代码。
  • @CRDave -- 仅当您想使用 UINavigationController 时。如果您不想使用该控制器,则必须自定义编码相同的转换。 xcode 如此难以打破 mvc 似乎很愚蠢(即,如果你有一个特定的控制器,你只能获得特定的转换),但它确实存在。

标签: xcode animation storyboard segue uistoryboardsegue


【解决方案1】:

对于这个简单的转场,你可以尝试这样的事情:

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

【讨论】:

    猜你喜欢
    • 2012-06-02
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 2015-09-30
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多