简体   繁体   English

如何修复过渡期间titleView被遮盖到导航栏?

[英]How to fix titleView being masked to navigation bar during transition?

In my view controller I am setting the titleView to a UIView which contains a UIImageView which is made into a circle using setCornerRadius on its layer. 在我的视图控制器中,我将titleView设置为一个UIView ,其中包含一个UIImageView ,使用该图层的setCornerRadius将其制成一个圆形。

The top half of the circle is positioned over the navbar, and the bottom half over the view, like this: 圆圈的上半部分位于导航栏上方,下半部分位于视图上方,如下所示:

一种

Now when I push this view controller, as it animates in, the bottom half of the circle is cut off until the animation completes. 现在,当我推入该视图控制器时,在动画化时,将切掉圆圈的下半部分,直到动画完成。 Only the part that's in the navbar is shown, something like this: 只有导航栏所示,像这样的部分:

乙

As soon as the push animation ends, the full circle is shown. 推送动画结束后,将显示整个圆圈。 Is there any way I can stop the navigation bar from masking/cutting off the titleView while the animation takes place, so that the full circle is shown during the animation? 有什么方法可以阻止动画titleView时导航栏掩盖/切断titleView ,以便在动画过程中显示整个圆圈?

I'm not sure you should want to do this. 我不确定您是否应该这样做。

Anyway: add the circle to your UIWindow (on top of your UINavigationController). 无论如何:将圆添加到UIWindow(在UINavigationController的顶部)。 I suppose you want to position the circle in the center of your screen (horizontally). 我想您想将圆放置在屏幕中央(水平)。 You can use a transition coordinator (iOS 7.0 +) to animate the circle alongside the transition of your view controller (push or pop). 您可以使用过渡协调器(iOS 7.0 +)在视图控制器(推或弹出)的过渡旁边为圆形设置动画。 Note that this only works for animated transitions (ie when animated is set). 请注意,这适用于过场动画(即当animated设置)。 Therefore, we need to set the new frame manually when animated isn't set. 因此,我们需要在未设置animated时手动设置新帧。

- (void)viewWillAppear:(BOOL)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;
    }
}

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

Now, you need to use a transition coordinator to animate the pop as well. 现在,您还需要使用过渡协调器来为流行音乐设置动画。

- (void)viewWillDisappear:(BOOL)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;
    }
}

And finally, remove the circle from your key window as soon as your view controller has disappeared (note that this does not necessarily mean your view controller is popped, and you can always readd the circle view to the key window again in viewWillAppear: ). 最后,一旦视图控制器消失,立即从关键窗口中删除该圆形(请注意,这不一定意味着您的视图控制器已弹出,您始终可以在viewWillAppear:再次将圆形视图读取到关键窗口中)。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导航栏titleView对齐 - Navigation bar titleView alignment 导航标题中添加了搜索栏 - Search bar added in navigation titleView 更改导航栏中标题视图的大小 - change size of titleview in navigation bar 如何在导航栏中更改titleView的大小。 因为navigationBar中的titleView和backButton之间存在差距 - How to change the size of titleView in navigation bar. Because there's a gap between titleView and backButton in navigationBar iOS:UINavigationController交互弹出手势期间,导航栏的全角自定义titleView闪烁 - iOS: Full width custom titleView of navigation bar flickers during interactive pop gesture of UINavigationController 在Facebook应用程序等推送/弹出过渡期间如何使titleView保留在UINavigationBar中? - How to make titleView remain in UINavigationBar during push/pop transition like Facebook app? 导航栏上的titleview在segues之后的视图中不可见 - titleview on navigation bar not visible in views after segues iOS 7在部分卷曲过渡期间,导航栏变为白色 - iOS 7 During partial curl transition the navigation bar turns white 在推送过渡期间响应导航栏高度变化 - Responding to navigation bar height changes during push transition 自定义序列转换期间,视图的导航栏项目放置不正确 - During custom segue transition, view's navigation bar items are misplaced
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM