【问题标题】:Working implementation of slide up/down transition using UINavigationControllerDelegate on iOS7在 iOS7 上使用 UINavigationControllerDelegate 实现上滑/下滑转换
【发布时间】:2014-02-27 17:58:36
【问题描述】:

我一直在尝试整理 iOS 7 中可用的自定义过渡动画。根据this questionUINavigationControllerDelegate 是要走的路。

但是,没有示例或文档描述如何最好地在 iOS7 中处理简单的垂直过渡。 (有一个plethora of other transition styles using UINavigationControllerDelegate,但没有一个像上下滑动视图那样简单——还有其他人建议只修改视图位置,但这似乎是一种俗气的技巧?)。还有others too that go as far back to 2011,但他们显然没有使用UINavigationControllerDelegate

谁能提供一个使用UINavigationControllerDelegate的简单上/下滑动转换的基本工作实现?

免责声明:我很乐意提供代码,但由于还没有任何代码可以发布...不过,我确实使用 jQuery 创建了一个简单的示例,展示了我想要实现的目标。

看看那个小提琴 here

【问题讨论】:

  • 我书中关于自定义过渡动画的部分非常好(即使我自己也这么说)。我的github site 有六个示例可以帮助您入门。这一点也不难(尽管我的书确实解释了一些可能不会立即显而易见的事情)。

标签: objective-c ios7 uinavigationcontroller transitions


【解决方案1】:

这是流程。我尽量简化。

【讨论】:

    【解决方案2】:

    还有其他人建议只修改视图位置,但这似乎是一种俗气的技巧

    不,这不是俗气的 hack。这就是你所做的。自定义过渡动画仅仅意味着您负责将新视图带入场景 - 只要它最终出现在正确的位置。因此,从底部对其进行动画处理的方法是将其放置在底部并对其进行动画处理。

    例如(几乎直接取自我书中的示例代码):

    -(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
        // boilerplate
        UIViewController* vc1 = 
            [transitionContext 
                viewControllerForKey:UITransitionContextFromViewControllerKey];
        UIViewController* vc2 = 
            [transitionContext  
                viewControllerForKey:UITransitionContextToViewControllerKey];
        UIView* con = [transitionContext containerView];
        CGRect r1start = [transitionContext initialFrameForViewController:vc1];
        CGRect r2end = [transitionContext finalFrameForViewController:vc2];
        UIView* v1 = vc1.view;
        UIView* v2 = vc2.view;
        // end boilerplate
    
        CGRect r = r2end;
        r.origin.y += r.size.height; // start at the bottom...
        v2.frame = r;
        [con addSubview:v2];
    
        [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
        [UIView animateWithDuration:0.4 animations:^{
            v2.frame = r2end; // ... and move up into place
        } completion:^(BOOL finished) {
            [transitionContext completeTransition:YES];
            [[UIApplication sharedApplication] endIgnoringInteractionEvents];
        }];
    }
    

    该代码改编自我在https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch06p292customAnimation1/ch19p620customAnimation1/AppDelegate.m 的示例,该示例几乎与您所描述的完全一样,只是它用于选项卡控制器而不是导航控制器,并且它来自侧面而不是底部。但原理完全一样。

    【讨论】:

    • 是的,这个例子很棒。再次感谢——我相信下一个寻找 up/down 实现的人也会很感激!
    猜你喜欢
    • 2011-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多