OGeek|极客世界-中国程序员成长平台

标题: ios - 如何修复titleView在过渡期间被隐藏到导航栏? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:22
标题: ios - 如何修复titleView在过渡期间被隐藏到导航栏?

在我的 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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4