将UINavigationBar从纯色动画为透明色

Fog*_*ter 8 objective-c uinavigationbar ios transition-coordinator

我试图在过渡期间将此应用程序的导航栏从纯色动画为透明色.

barStyletranslucent性质也改变为新的视图控制器.

我这样做的原因是因为我们使用透明导航栏并在滚动期间将其淡入...

- (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];
}
Run Code Online (Sandbox Code Playgroud)

这在滚动时工作正常,但为了获得透明导航栏,您必须使用该backgroundImage属性navigationBar.如果您尝试使用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];
 }];
Run Code Online (Sandbox Code Playgroud)

显然,这会将颜色从原始颜色设置为themeColor具有100%alpha 的视图控制器属性,然后当转换完成后,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];
 }];
Run Code Online (Sandbox Code Playgroud)

但这只是将它设置为0%alpha而没有动画的最终图像.

我正在寻找一种方法,从原始颜色的100%alpha动画到themeColor过渡期间的0%alpha .因此,条形图将从(例如)蓝色到红色以及1.0 alpha到0.0 alpha进行动画处理.

这甚至可能吗?谁知道怎么样?