加入收藏 | 设为首页 | 会员中心 | 我要投稿 无忧刷机网 - 51刷机网 (https://www.51shuaji.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 苹果频道 > 苹果资讯 > 正文

iOS Navigation导航栏

发布时间:2017-05-19 20:26:35 所属栏目:苹果资讯 来源:www.jianshu.com
导读:在iOS开发过程中,导航栏是最为经常用到的控件,处理不好总会出现一些瑕疵或者bug,写这篇文章旨在为自己记录平时所用有关Navigation一些操作或者说是小技巧。下文涉及到的push逻辑都是从A页面push到B页面,我会直接以A、B介绍...

使用[self.navigationController setNavigationBarHidden:NO animated:YES] 侧滑手势会被禁,所以需要加代理开启手势

- (void)viewDidLoad {     [super viewDidLoad];     //设置代理     if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {         self.navigationController.interactivePopGestureRecognizer.delegate = self;     } } - (void)viewWillAppear:(BOOL)animated {     [super viewWillAppear:animated];     //会导致侧滑手势被禁     [self.navigationController setNavigationBarHidden:YES animated:animated]; } - (void)viewWillDisappear:(BOOL)animated {     [super viewWillDisappear:animated];     //如果该控制器没有上级控制器,建议将使用[self.navigationController setNavigationBarHidden:NO animated:animated] 效果会更好点     [self.navigationController setNavigationBarHidden:NO animated:NO]; } #pragma mark - UIGestureRecognizerDelegate - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {     return YES; }
2、导航栏渐变

介绍两个方法:

//隐藏导航栏,但不隐藏上面的Item [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init]                                               forBarMetrics:UIBarMetricsDefault]; //隐藏导航栏底部那条线 [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];

这个不做演示,推荐一个三方 LTNavigationBar

三、自定义TitleView

直接上代码

UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)]; UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; switchView.center = titleView.center; [titleView addSubview:switchView]; self.navigationItem.titleView = titleView;
iOS Navigation导航栏
自定义TitleView

(编辑:无忧刷机网 - 51刷机网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读