• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 如何修复titleView在过渡期间被隐藏到导航栏?

[复制链接]
菜鸟教程小白 发表于 2022-12-12 16:22:34 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

在我的 View Controller 中,我将 titleView 设置为一个 UIView,其中包含一个 UIImageView 使用 setCornerRadius 将其制成一个圆圈层。

圆圈的上半部分位于导航栏上方,下半部分位于 View 上方,如下所示:

A

现在,当我插入这个 View Controller 时,当它动画化时,圆的下半部分被切断,直到动画完成。仅显示导航栏 in 的部分,如下所示:

B

推送动画一结束,就会显示完整的圆圈。有什么方法可以阻止导航栏在动画发生时屏蔽/切断 titleView ,以便在动画期间显示完整的圆圈?



Best Answer-推荐答案


我不确定你是否应该这样做。

无论如何:将圆圈添加到您的 UIWindow(在您的 UINavigationController 顶部)。我想你想把圆圈放在屏幕的中心(水平)。您可以使用过渡协调器(iOS 7.0 +)在 View Controller (推或弹出)的过渡旁边为圆圈设置动画。请注意,这 only 适用于动画过渡(即当设置 animated 时)。因此,当 animated 没有设置时,我们需要手动设置新的帧。

- (void)viewWillAppearBOOL)animated {
    [super viewWillAppear:animated];

    /* Add the circle to the key window (instead of the navigation bar). */
    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
    [keyWindow addSubview:_circle];

    /* Screen width: the initial position of the circle = center + screen width. */
    CGFloat width = self.view.bounds.size.width;

    CGRect destination = _circle.frame;
    destination.origin.x = 110.f;

    /* The transition coordinator is only available for animated transitions. */
    if (animated) {
        CGRect frame = destination;
        frame.origin.x += width;
        _circle.frame = frame;

        void (^animation)(id context) = ^(id context) {
            _circle.frame = destination;
        };

        [self.transitionCoordinator animateAlongsideTransitionInView:_circle
                                                           animation:animation
                                                          completion:animation];
    }else {
        _circle.frame = destination;
    }
}

110.f 替换为您的位置 (110.f = ((320.f - 100.f)/2.f))。

现在,您还需要使用过渡协调器来为 pop 设置动画。

- (void)viewWillDisappearBOOL)animated {
    [super viewWillDisappear:animated];

    /* Screen width: the initial position of the circle = center + screen width. */
    CGFloat width = self.view.bounds.size.width;

    CGRect destination = _circle.frame;
    destination.origin.x = 110.f + width;

    /* The transition coordinator is only available for animated transitions. */
    if (animated) {
        CGRect frame = destination;
        frame.origin.x = 110.f;
        _circle.frame = frame;

        void (^animation)(id context) = ^(id context) {
            _circle.frame = destination;
        };

        [self.transitionCoordinator animateAlongsideTransitionInView:_circle
                                                           animation:animation
                                                          completion:animation];
    }else {
        _circle.frame = destination;
    }
}

最后,一旦你的 View Controller 消失,从你的关键窗口中删除圆圈(注意这并不一定意味着你的 View Controller 被弹出,你总是可以在 viewWillAppear:).

- (void)viewDidDisappearBOOL)animated {
    [super viewDidDisappear:animated];

    /* Remove the circle from your key window. */
    [_circle removeFromSuperview];
}

关于ios - 如何修复titleView在过渡期间被隐藏到导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19939028/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap