在iOS7上使用UINavigationControllerDelegate实现上滑/下移过渡的实现

bra*_*ipt 3 objective-c transitions uinavigationcontroller ios7

我花了一些时间尝试整理iOS 7中提供的自定义过渡动画.根据这个问题,UINavigationControllerDelegate是要走的路.

但是,没有示例或文档描述如何最好地在iOS7中进行简单的垂直过渡.(有很多其他的过渡样式使用UINavigationControllerDelegate,但没有一个像上下滑动视图一样简单 - 还有其他的建议只是修改视图位置,但这似乎是一个俗气的黑客?).还有其他人可以追溯到2011年,但他们显然没有使用UINavigationControllerDelegate.

任何人都可以使用UINavigationControllerDelegate?提供简单的上下滑动过渡的基本工作实现吗?

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

看看那个小提琴 here

mat*_*att 6

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

不,这不是一个俗气的黑客.那就是你做的.自定义过渡动画只是意味着您负责将新视图带入场景 - 前提是它最终位于正确的位置.因此,从底部对其进行动画处理的方法就是将其放置在底部并将其动画到位.

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

-(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];
    }];
}
Run Code Online (Sandbox Code Playgroud)

该代码改编自我的例子https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch06p292customAnimation1/ch19p620customAnimation1/AppDelegate.m这个例子几乎就是你所描述的,除了它是为了一个选项卡控制器而不是导航控制器,它从侧面而不是从底部进入.但原则完全相同.