【问题标题】:Custom animation while transitioning between view controllers在视图控制器之间转换时自定义动画
【发布时间】:2015-12-19 00:45:28
【问题描述】:

我想像这样在视图控制器之间创建过渡。 https://www.dropbox.com/s/qatwqaq2mowocsg/Transitions%20Controller.gif?dl=0

我已使用以下代码创建过渡,但无法实现以下结果。

self.settings = [self.storyboard instantiateViewControllerWithIdentifier:@"settings"];
CATransition* transition = [CATransition animation];

transition.duration = 0.4;
transition.type = kCATransitionPush;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.subtype=kCATransitionFromRight;


[[self navigationController].view.layer addAnimation:transition forKey:kCATransition];
[[self navigationController] pushViewController:self.settings animated:NO];

【问题讨论】:

    标签: ios objective-c cocoa-touch uikit core-animation


    【解决方案1】:

    你可以试试这个代码:

    self.settings = [self.storyboard instantiateViewControllerWithIdentifier:@"settings"];
    
    [UIView beginAnimations:@"View Flip" context:nil];
    [UIView setAnimationDuration:0.80];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    
    [UIView setAnimationTransition:
     UIViewAnimationTransitionFlipFromRight
                           forView:self.navigationController.view cache:NO];
    
    
    [self.navigationController pushViewController:self.settings animated:YES];
    [UIView commitAnimations];
    

    【讨论】:

    • 这段代码sn-p只执行UIViewAnimationTransitionFlipFromRight动画,曲线(UIViewAnimationCurveEaseInOut)对动画没有影响。
    【解决方案2】:

    从iOS7开始可以自定义系统方法pushViewController和presentViewController的过渡效果。例如,如果你需要自定义推送效果,UINavigationControllerDelegate 中有一个名为

    的方法
    - (id<UIViewControllerAnimatedTransitioning> _Nullable)navigationController:(UINavigationController * _Nonnull)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController * _Nonnull)fromVC toViewController:(UIViewController * _Nonnull)toVC
    

    将自定义动画添加到 fromVC 的视图中,并在适当的时间显示 toVC 的视图

    【讨论】:

    • 我使用了这种方法,并使用上面的代码将一个新对象压入堆栈。但我观察到的唯一效果是“fromVC 被翻转了一点,但 toVC 水平滑动。”
    【解决方案3】:

    虽然它不是代表THE ANSWER 的直接可实现代码块,但此博客应该会引导您完成创建自己的自定义转换的步骤:http://blog.dadabeatnik.com/2013/10/13/custom-segues/

    【讨论】:

    • 感谢分享这个博客。我在自定义 segue 上搜索了太多。但我的问题仍然存在,卡在实现以下要求。
    • 什么是“以下要求”?你的意思是你被困在如何实际实现你发布的 gif 上?是需要弄清楚如何将动画分解为完成它需要做的事情还是有某种错误?
    • 是的,我一直坚持实际实现 gif。
    猜你喜欢
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    相关资源
    最近更新 更多