【问题标题】:UINavigationController: pop view controller in the opposite directionUINavigationController:反方向弹出视图控制器
【发布时间】:2011-12-23 06:35:51
【问题描述】:

我正在尝试调用[[self navigationController] popViewControllerAnimated:YES],但使动画从右向左滑动而不是从左向右滑动。有什么简单的方法可以做到这一点?我想回到以前的视图。任何帮助表示赞赏。谢谢!

【问题讨论】:

    标签: iphone ios animation uinavigationcontroller


    【解决方案1】:

    这就是如何以相反的方向弹出视图控制器。它对我有用 100%

    CATransition *transition = [CATransition animation];
        transition.duration = 0.45;
        transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
        transition.type = kCATransitionFromRight;
        [transition setType:kCATransitionPush];
        transition.subtype = kCATransitionFromRight;
        [self.navigationController.view.layer addAnimation:transition forKey:nil];
        [self.navigationController popViewControllerAnimated:NO];
    

    【讨论】:

    • 这就是我要找的!!谢谢。
    • 你设置了两次类型? transition.type = kCATransitionPush 应该足够了。
    【解决方案2】:

    有可能,请查看我不久前使用的以下代码,并尝试使其适合自己。余只需要改setAnimationTransition

    [UIView  beginAnimations:nil context:NULL];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
    [UIView commitAnimations];
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelay:0.375];
    [self.navigationController popViewControllerAnimated:NO];
    [UIView commitAnimations];
    

    有几种不同类型的默认动画可供使用,苹果网站说这种动画是可能的:

    typedef enum {
       UIViewAnimationTransitionNone,
       UIViewAnimationTransitionFlipFromLeft,
       UIViewAnimationTransitionFlipFromRight,
       UIViewAnimationTransitionCurlUp,
       UIViewAnimationTransitionCurlDown,
    } UIViewAnimationTransition;
    

    因此,在您的情况下,您需要使用以下内容:

        [UIView  beginAnimations:nil context:nil];
        [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.75];
        [self.navigationController popViewControllerAnimated:NO];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
        [UIView commitAnimations];
    

    【讨论】:

    • 谢谢。有没有办法像打电话一样滑动它pushViewController
    • 是的,就像我说的,你只需要在这里改行:[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
    • 我明白这一点。但是我找不到正确的过渡。
    • 只是没有一个人做我想让他们做的事。我希望它具有与 UINavigationController 推送新视图控制器完全相同的动作
    • 确实如此,我会编辑我的帖子来制作这个动画,这正是你想要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 2012-12-23
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多