Change the alpha value of the navigation bar

后端 未结 9 1693
误落风尘
误落风尘 2020-12-08 05:55

Is this possible?

I want to change the alpha value of the navigation bar in my view controller (in an animation), but if I do self.navigationController.navigat

9条回答
  •  天命终不由人
    2020-12-08 06:17

    If you just want to get rid of the navigationBar in an animated way you could do:

    [self.navigationController setNavigationBarHidden:YES animated:YES];
    

    If you want to control the animation and its necessary to set the alpha to 0.0, read on:

    The "black box" you are seeing is from the underlying view or window. If you just want your views color instead of the "black box" do:

    self.navigationController.view.backgroundColor = self.view.backgroundColor;
    
    [UIView animateWithDuration:1.0 delay:1.0 options:0 animations:^{
        self.navigationController.navigationBar.alpha = 0.0;
    } completion:NULL];
    

    If you want your actual view to be where the navigationBar was, you need to increase the height of your view:

    [UIView animateWithDuration:1.0 delay:1.0 options:0 animations:^{
        self.navigationController.navigationBar.alpha = 0.0;
    
        CGFloat navigationBarHeight = self.navigationController.navigationBar.frame.size.height;
    
        CGRect frame = self.view.frame;
        frame.origin.y -= navigationBarHeight;
        frame.size.height += navigationBarHeight;
        self.view.frame = frame;
    } completion:NULL];
    

提交回复
热议问题