這篇文章將為大家詳細(xì)講解有關(guān)iOS如何導(dǎo)航欄無縫圓滑的隱藏Navigationbar,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
十多年的陜州網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。營(yíng)銷型網(wǎng)站的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整陜州建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“陜州網(wǎng)站設(shè)計(jì)”,“陜州網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
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 ()
代理方法
- (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è)頁(yè)面"; [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 ()
手勢(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; // } // } }
效果圖
關(guān)于“iOS如何導(dǎo)航欄無縫圓滑的隱藏Navigationbar”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。