iOS 導(dǎo)航欄無縫圓滑的隱藏 Navigationbar實(shí)例代碼
1.ViewController
.m
- (void)viewDidLoad { [super viewDidLoad]; self.title = @"隱藏導(dǎo)航欄"; 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{ ///跳轉(zhuǎn)到KKViewController [self performSegueWithIdentifier:@"pusht" sender:nil]; }
頭部代理
@interface ViewController ()<UINavigationControllerDelegate>
代理方法
- (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(目標(biāo)ViewController)
新建一個(gè)KKViewController
.h
@property (nonatomic,strong) id popDelegate;
.m
- (void)viewDidLoad { [super viewDidLoad]; self.title = @"第二個(gè)頁面"; [self popSet]; } - (void)popSet{ _popDelegate = self.navigationController.interactivePopGestureRecognizer.delegate; SEL action = NSSelectorFromString(@"handleNavigationTransition:"); UIPanGestureRecognizer *popPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self.popDelegate action:action]; popPanGesture.maximumNumberOfTouches = 1; popPanGesture.delegate = self; [self.view addGestureRecognizer: popPanGesture]; }
頭部代理
@interface KKViewController ()<UIGestureRecognizerDelegate>
手勢(shì)代理方法
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer{ ///【下面兩個(gè)方法寫一個(gè)】 ///全屏拖動(dòng) CGPoint tragPoint = [gestureRecognizer translationInView:gestureRecognizer.view]; if (tragPoint.x <= 0){ return NO; } else{ if (self.navigationController.viewControllers.count <= 1){ return NO; } else{ return YES; } } // ///局部允許拖動(dòng) // CGPoint tragPoint = [gestureRecognizer locationInView:gestureRecognizer.view]; // NSLog(@"x=%f;y=%f",tragPoint.x,tragPoint.y); // if (tragPoint.x > 60){///拖動(dòng)的范圍 // return NO; // } // else{ // if (self.navigationController.viewControllers.count <= 1) { // return NO; // } // else{ // return YES; // } // } }
效果圖
總結(jié)
以上所述是小編給大家介紹的iOS 導(dǎo)航欄無縫圓滑的隱藏 Navigationbar,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
cmake ios終端下執(zhí)行提示錯(cuò)誤 iOS version not found, tested: [5.0;5.1;6
這篇文章主要介紹了cmake ios終端下執(zhí)行提示錯(cuò)誤 iOS version not found, tested: [5.0;5.1;6.0;6.1;7.0;8.3]的解決方案的相關(guān)資料,需要的朋友可以參考下2016-10-10iOS漸變圓環(huán)旋轉(zhuǎn)動(dòng)畫CAShapeLayer CAGradientLayer
這篇文章主要介紹了iOS漸變圓環(huán)旋轉(zhuǎn)動(dòng)畫CAShapeLayer CAGradientLayer的相關(guān)資料,需要的朋友可以參考下2016-09-09iOS開發(fā)使用UITableView制作N級(jí)下拉菜單的示例
這篇文章主要介紹了iOS開發(fā)使用UITableView制作N級(jí)下拉菜單的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01iOS開發(fā)中實(shí)現(xiàn)新聞圖片的無限循環(huán)展示的方法
這篇文章主要介紹了iOS開發(fā)中實(shí)現(xiàn)新聞圖片的無限循環(huán)展示的方法,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2015-12-12IOS 開發(fā)之UISearchBar 詳解及實(shí)例
這篇文章主要介紹了IOS 開發(fā)之UISearchBar 詳解及實(shí)例的相關(guān)資料,主要介紹 IOS UISearchBar的使用,附有實(shí)例代碼,需要的朋友可以參考下2016-12-12