gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:38:51 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com