IOS-hide Navigationbar [seamless and smooth navigation bar hiding] and ios-navigationbar

Source: Internet
Author: User

IOS-hide Navigationbar [seamless and smooth navigation bar hiding] and ios-navigationbar
1. ViewController

. M

-(Void) viewDidLoad {[super viewDidLoad]; self. title = @ "Hide navigation bar"; UIButton * button = [UIButton buttonWithType: UIButtonTypeCustom]; button. backgroundColor = [UIColor lightGrayColor]; button. frame = CGRectMake (10,100, 60, 30); [button addTarget: self action: @ selector (buttonClick) forControlEvents: UIControlEventTouchUpInside]; [self. view addSubview: button]; self. navigationController. delegate = self;}-(void) buttonClick {// jump to KKViewController [self defined mseguewithidentifier: @ "pusht" sender: nil];}

Header proxy

@interface ViewController ()<UINavigationControllerDelegate>

Proxy Method

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {        [self.navigationController setNavigationBarHidden: [self hiddenBarVc: viewController] animated: animated];}- (BOOL)hiddenBarVc:(UIViewController *)viewController {        BOOL needHideNaivgaionBar = NO;        if ([viewController isKindOfClass: [KKViewController class]]) {        needHideNaivgaionBar = YES;    }        return needHideNaivgaionBar;}
2. KKViewController (target ViewController)

Create a KKViewController

. H

@property (nonatomic,strong) id popDelegate;

. M

-(Void) viewDidLoad {[super viewDidLoad]; self. title = @ "second page"; [self popSet];}-(void) popSet {_ popDelegate = self. navigationController. interactivepopgsturerecognizer. delegate; SEL action = NSSelectorFromString (@ "handleNavigationTransition:"); UIPanGestureRecognizer * popPanGesture = [UIPanGestureRecognizer alloc] initWithTarget: self. popDelegate action: action]; popPanGesture. maximumNumberOfTouches = 1; popPanGesture. delegate = self; [self. view addGestureRecognizer: popPanGesture];}

Header proxy

@interface KKViewController ()<UIGestureRecognizerDelegate>

Gesture proxy method

-(BOOL) Merge :( optional *) gestureRecognizer {// [write one of the following two methods] // drag CGPoint tragPoint = [gestureRecognizer translationInView: gestureRecognizer in full screen mode. view]; if (tragPoint. x <= 0) {return NO;} else {if (self. navigationController. viewControllers. count <= 1) {return NO;} else {return YES ;}//// allow local drag // CGPoint tragPoint = [gestureRecognizer locationInView: gestureRecognizer. view]; // NSLog (@ "x = % f; y = % f", tragPoint. x, tragPoint. y); // if (tragPoint. x> 60) {// drag range // return NO; //} // else {// if (self. navigationController. viewControllers. count <= 1) {// return NO; //} // else {// return YES ;//}//}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.