iOS-隱藏Navigationbar【導覽列無縫圓滑的隱藏】,ios-navigationbar

來源:互聯網
上載者:User

iOS-隱藏Navigationbar【導覽列無縫圓滑的隱藏】,ios-navigationbar
1.ViewController

.m

- (void)viewDidLoad {    [super viewDidLoad];    self.title = @"隱藏導覽列";    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{    ///跳轉到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(目標ViewController)

建立一個KKViewController

.h

@property (nonatomic,strong) id popDelegate;

.m

- (void)viewDidLoad {    [super viewDidLoad];    self.title = @"第二個頁面";    [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>

手勢代理方法

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer{        ///【下面兩個方法寫一個】    ///全屏拖動    CGPoint tragPoint = [gestureRecognizer translationInView:gestureRecognizer.view];    if (tragPoint.x <= 0){        return NO;    }    else{        if (self.navigationController.viewControllers.count <= 1){            return NO;        }        else{            return YES;        }    }        //    ///局部允許拖動//    CGPoint tragPoint = [gestureRecognizer locationInView:gestureRecognizer.view];//    NSLog(@"x=%f;y=%f",tragPoint.x,tragPoint.y);//    if (tragPoint.x > 60){///拖動的範圍//        return NO;//    }//    else{//        if (self.navigationController.viewControllers.count <= 1) {//            return NO;//        }//        else{//            return YES;//        }//    }}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.