static CGFloat navBarOriginY = 20.0;
Create constant for base value of navigation bar origin Y position
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.hidesBarsOnSwipe = true;
[self.navigationController.barHideOnSwipeGestureRecognizer addTarget:self action:@selector(swipe:)];
}
Add your custom selector to handle system swipe gesture that will fire before navBar become hidden and during hiding
- (void)swipe:(UIPanGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled || recognizer.state == UIGestureRecognizerStateFailed) {
If gesture state ended/canceled or failed you need entirely change frame of tabBar
CGRect finalFrame = self.tabBarController.tabBar.frame;
if (self.navigationController.navigationBar.frame.origin.y < 0) {
//Tab bar will be hidden
finalFrame.origin.y = self.maxTabBarY;
} else {
//Tab bar will be visible
finalFrame.origin.y = self.minTabBarY;
}
[self setFrameForTabBar:finalFrame animationDuration:0.3];
} else if (recognizer.state == UIGestureRecognizerStateChanged) {
If state == changed than you need to pan your tabBar with navBar like in safari app.
CGRect frame = self.tabBarController.tabBar.frame;
CGFloat delta = navBarOriginY - self.navigationController.navigationBar.layer.presentationLayer.frame.origin.y;
frame.origin.y = self.minTabBarY + delta;
[self setFrameForTabBar:frame animationDuration:0.0];
} } }
- (void)setFrameForTabBar:(CGRect)frame animationDuration:(CGFloat)duration {
dispatch_async(dispatch_get_main_queue(), ^{
[UIView animateWithDuration:duration delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
self.tabBarController.tabBar.frame = frame;
} completion:^(BOOL finished) {}];
});