CNLiveBaseViewController.m 2.63 KB
//
//  CNLiveBaseViewController.m
//  CNLiveBaseClass
//
//  Created by CNLive-zxw on 2019/12/13.
//  Copyright © 2019 153993236@qq.com. All rights reserved.
//

#import "CNLiveBaseViewController.h"
#import "CNLiveNavigationBar.h"

@interface CNLiveBaseViewController ()
@property (nonatomic, strong) CNLiveNavigationBar *navigationBar;

@end

@implementation CNLiveBaseViewController
#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    // 禁止页面左侧滑动返回,注意,如果仅仅需要禁止此单个页面返回,还需要在viewWillDisapper下开放侧滑权限
    // 禁用返回手势
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = self.interactive;
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self createSubViews];
}

#pragma mark - UI
- (void)createSubViews{
    [self.view addSubview:self.navigationBar];
}

#pragma mark - Setter方法
- (void)setTitle:(NSString *)title{
    [super setTitle:title];
    self.navigationBar.title.text = title;
}

- (void)setNavigationHidden:(BOOL)navigationHidden{
    _navigationHidden = navigationHidden;
    _navigationBar.hidden = navigationHidden;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - 响应方法
- (void)goBack {
    if (self.presentingViewController != nil) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

#pragma mark - 懒加载
- (CNLiveNavigationBar *)navigationBar {
    if (!_navigationBar) {
        _navigationBar = [CNLiveNavigationBar navigationBar];
        _navigationBar.title.text = self.title;
        __weak typeof(self) weakSelf = self;
        _navigationBar.onClickLeftButton = ^{
            __strong typeof(weakSelf) strongSelf = weakSelf;
            if(!strongSelf) return ;
            [strongSelf goBack];
        };
    }
    return _navigationBar;
}

@end