Animate a UINavigationBar's barTintColor

前端 未结 3 1390
[愿得一人]
[愿得一人] 2021-02-02 04:22

The app I\'m working on changes the barTintColor of its navigation bar when pushing new view controllers. Right now we set that colour in the destination view contr

3条回答
  •  旧时难觅i
    2021-02-02 04:54

    You can add extra animations that match the timing and animation curve of the view controller transition using UIViewControllerTransitionCoordinator.

    A view controller's transitionCoordinator will be set after a view controller's animation has started (so in viewWillAppear of the presented view controller). Add any extra animations using animateAlongsideTransition:completion: on the transition coordinator.

    An example:

    [[self transitionCoordinator] animateAlongsideTransition:^(id context) {
        self.navigationController.navigationBar.translucent = NO;
        self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
        self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
        self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    } completion:nil];
    

提交回复
热议问题