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

标签 ios objective-c animation uinavigationcontroller titleview

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

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

A

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

B

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

最佳答案

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

无论如何:将圆圈添加到您的 UIWindow(在您的 UINavigationController 之上)。我想您想将圆圈放置在屏幕中央(水平)。您可以使用过渡协调器 (iOS 7.0 +) 在 View Controller 的过渡(推送或弹出)旁边为圆圈设置动画。请注意,这适用于动画过渡(即设置animated 时)。因此,当未设置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;
    }
}

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

现在,您还需要使用过渡协调器来为流行音乐制作动画。

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

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

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

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

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

相关文章:

objective-c - 为什么 Objective-C 在 Apple 社区之外不是很流行?

javascript - Jquery 或 Javascript 动画 Z-索引

python - 一个步骤的 Matplotlib 动画

objective-c - 使用 UIViewAnimationOptionTransitionCurlDown 自定义 Segue

ios - AirPlay 镜像的欠扫描问题

ios - Restkit:未调用 RKRequest 委托(delegate)

ios - 如何使用调试配置指定项目的自定义 xcconfig

objective-c - ARC 是否足够聪明以释放父类(super class)中定义的 subview ?

html - 在网页中间创建响应式表单

ios - Xcode Storyboard 中的对象消失