iOS 7 UINavigationController NavBar per controller color animation

旧街凉风 提交于 2019-11-28 08:45:48

You can get this by using UIViewControllerTransitionCoordinator.

  1. Copy the example code to the AController and customize the colors.
  2. Copy the example code to the BController and customize the colors.
  3. That's it! During UINavigationController's push/pop transition, the AController's style will smoothly fade in/out to BController's style.

Example code:

-(void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    [[self transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
        self.navigationController.navigationBar.translucent = NO;
        self.navigationController.navigationBar.barStyle = UIBarStyleDefault;

        // text color
        [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];

        // navigation items and bar button items color
        self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

        // background color
        self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
    } completion:nil];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!