FLEXNavigationController.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // FLEXNavigationController.m
  3. // FLEX
  4. //
  5. // Created by Tanner on 1/30/20.
  6. // Copyright © 2020 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXNavigationController.h"
  9. @interface UINavigationController (Private) <UIGestureRecognizerDelegate>
  10. - (void)_gestureRecognizedInteractiveHide:(UIGestureRecognizer *)sender;
  11. @end
  12. @interface UIPanGestureRecognizer (Private)
  13. - (void)_setDelegate:(id)delegate;
  14. @end
  15. @interface FLEXNavigationController ()
  16. @property (nonatomic, readonly) BOOL toolbarWasHidden;
  17. @property (nonatomic) BOOL waitingToAddTab;
  18. @end
  19. @implementation FLEXNavigationController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. self.waitingToAddTab = YES;
  23. }
  24. - (void)_gestureRecognizedInteractiveHide:(UIPanGestureRecognizer *)sender {
  25. if (sender.state == UIGestureRecognizerStateRecognized) {
  26. BOOL show = self.topViewController.toolbarItems.count;
  27. CGFloat yTranslation = [sender translationInView:self.view].y;
  28. CGFloat yVelocity = [sender velocityInView:self.view].y;
  29. if (yVelocity > 2000) {
  30. [self setToolbarHidden:YES animated:YES];
  31. } else if (show && yTranslation > 20 && yVelocity > 250) {
  32. [self setToolbarHidden:NO animated:YES];
  33. } else if (yTranslation < -20) {
  34. [self setToolbarHidden:YES animated:YES];
  35. }
  36. }
  37. }
  38. @end