Auto Layout and “Hide bottom bar when pushed”

后端 未结 10 1947
Happy的楠姐
Happy的楠姐 2021-01-30 12:54

My app\'s (simplified) structure is this:

UITabBarController with one UINavigationController holding a UITableViewController as ro

相关标签:
10条回答
  • 2021-01-30 13:35

    If you want the tab bar to be hidden, you can add this code to your controller,

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        self.tabBarController.tabBar.hidden = YES;
    }
    

    You will also have to put that code (but passing NO) into the controller where you want the tab bar to be visible. You should also deselect the "Hide bottom bar when pushed" box in IB.

    After Edit:

    You'll get a better animation if, in the first controller, you animate the alpha value of the non-hidden tab bar from 0 to 1 over a short time. This looks good if you go back with the back button. If you want to use the swipe back, you would have to do something more complicated involving the interactivePopGestureRecognizer.

    -(void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        self.tabBarController.tabBar.hidden = NO;
        self.tabBarController.tabBar.alpha = 0.0;
        [UIView animateWithDuration:.4 animations:^{
            self.tabBarController.tabBar.alpha = 1.0;
        }];
    }
    
    0 讨论(0)
  • 2021-01-30 13:40

    The accepted answer did not work for me (the option was not available). However I have found another solution. (based on Hide Bottom Bar When Pushed through Autolayout)

    Select booth the view and the object to align (in my case btnShare) and add a new alignment constraint (Bottom Edges).

    0 讨论(0)
  • 2021-01-30 13:40
    -(void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        self.tabBarController.tabBar.hidden = NO;
        self.tabBarController.tabBar.alpha = 0.0;
        [UIView animateWithDuration:.3 animations:^{
            self.tabBarController.tabBar.alpha = 5.0;
        }];
    }
    
    0 讨论(0)
  • 2021-01-30 13:46

    Try pinning bottom of your view to bottom of superview and not bottom-layout

    0 讨论(0)
  • 2021-01-30 13:48

    The problem is with this specific constraint which is between the view and the top of the bottom layout guide.

    enter image description here

    Select the constraint and edit its "Second Item" property

    enter image description here

    Here you need to choose bottom

    enter image description here

    Once you have that, the pink view is not influenced by layout guide anymore. The layout guide seem to acknowledge that the tab bar is hidden only after the root view of the pushed view controller is in the bounds of main screen and this happens only when the animation is finished.

    And that is the reason the view hierarchy needs to be laid out again which causes the unwanted animation.

    0 讨论(0)
  • 2021-01-30 13:51

    Hi In storyboard select Tab bar (Is Tab Bar Controller Scene > Tab Bar Controller > Tab Bar ), in the attribute inspector, uncheck Translucent box. This action fix your problem. (But there are many things, "Hide bottom bar when pushed" is to toolbar).

    0 讨论(0)
提交回复
热议问题