[英]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.