如何解决titleview的被过渡期间蒙面导航栏? [英] How to fix titleView being masked to navigation bar during transition?

查看:336
本文介绍了如何解决titleview的被过渡期间蒙面导航栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的视图控制器我设置了 titleview的的UIView 包含一个的UIImageView 它被做成了层上使用setCornerRadius一个圆圈。

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.

圆的上半部分被放置在导航栏,并在视图的下半部分,是这样的:

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:

一旦推动画结束,则全圆显示。有没有什么办法可以阻止屏蔽/切断导航栏中的 titleview的而动画发生,使动画过程中显示完整的圆?

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?

推荐答案

我不知道,你应该想这样做。

I'm not sure you should want to do this.

总之:加圈的一个UIWindow(您UINavigationController的顶部)。我想你想放置在圆形屏幕(水平)的中心。您可以使用一个过渡协调员(的iOS 7.0 +),以动画的圆圈旁边您的视图控制器(PUSH或POP)的过渡。请注意,这的只有的适用于过场动画时(即当动画设置)。因此,我们需要手动设置新的帧时动画未设置。

Anyway: add the circle to your UIWindow (on top of your 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). Note that this only works for animated transitions (i.e. when animated is set). Therefore, we need to set the new frame manually when animated isn't set.

- (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;
    }
}

替换 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;
    }
}

最后,只要您的视图控制器已经消失移除你的关键窗口圆(注意,这并不一定意味着你的视图控制器弹出,你总是可以再次重新进行添加圈内视图的关键窗口 viewWillAppear中:

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

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

这篇关于如何解决titleview的被过渡期间蒙面导航栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆