加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 在iOS7上使用UINavigationControllerDelegate实

发布时间:2020-12-16 09:50:16 所属栏目:百科 来源:网络整理
导读:我花了一些时间尝试整理iOS 7中提供的自定义过渡动画.根据 this question,UINavigationControllerDelegate是要走的路. 但是,没有示例或文档描述如何最好地在iOS7中进行简单的垂直过渡. (有一个plethora of other transition styles using UINavigationContro
我花了一些时间尝试整理iOS 7中提供的自定义过渡动画.根据 this question,UINavigationControllerDelegate是要走的路.

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

Can anyone provide a basic working implementation of a simple slide up/down transition using UINavigationControllerDelegate?

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

看看小提琴here

解决方法

there are others that suggest just modifying the view position,but that seems like a tacky 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的例子改编的.这个例子几乎就是你所描述的,除了它是一个标签控制器而不是导航控制器,它来自侧面而不是底部.但原则完全一样.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读