我试图在过渡期间将此应用程序的导航栏从纯色动画为透明色 .
barStyle
和 translucent
属性也会针对新视图控制器进行更改 .
我这样做的原因是因为我们使用透明导航栏并在滚动期间将其淡入...
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat maxY = self.headerHeight - 64;
CGFloat percentage = MIN(0.996, MAX(0, [self alphaFromPercentageWithEasing:offsetY / maxY]));
[self.navigationController.navigationBar setBackgroundImage:[UIColor imageFromColor:self.themeColor alpha:percentage] forBarMetrics:UIBarMetricsDefault];
}
这在滚动时工作正常,但为了获得透明导航栏,您必须使用 navigationBar
的 backgroundImage
属性 . 如果您尝试使用 alpha
小于1的颜色,则使用alpha为1的颜色 . 因此,您不能只使用透明颜色 .
我遇到的问题是在转换期间我有 transitionCoordinator
这样做...
[self.transitionCoordinator
animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
self.navigationController.navigationBar.barTintColor = self.themeColor;
}
completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
// this is so that when popping back to here the bar alpha
// is set correctly from the current scroll position
[self scrollViewDidScroll:self.tableView];
}];
显然,这会将颜色从原始颜色设置为具有100%alpha的视图控制器的 themeColor
属性,然后当转换完成时, navigationBar
就会消失 .
我甚至尝试过在图像之间制作动画......
[self.navigationController.navigationBar setBackgroundImage:[UIColor imageFromColor:originalColor alpha:1.0] forBarMetrics:UIBarMetricsDefault];
[self.transitionCoordinator
animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
[self.navigationController.navigationBar setBackgroundImage:[UIColor imageFromColor:self.themeColor alpha:0] forBarMetrics:UIBarMetricsDefault];
}
completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
// this is so that when popping back to here the bar alpha
// is set correctly from the current scroll position
[self scrollViewDidScroll:self.tableView];
}];
但这只是将它设置为0%alpha而没有动画的最终图像 .
我正在寻找一种方法,在过渡期间从原始颜色的100%alpha动画到 themeColor
的0%alpha . 因此,条形图将从(例如)蓝色到红色以及1.0 alpha到0.0 alpha进行动画处理 .
这甚至可能吗?谁知道怎么样?