zoukankan      html  css  js  c++  java
  • iOS7以上自定义一个navigationController,并沿用系统的侧滑返回效果

    首先需要子类化一个navigationController的子类,在init方法中对定制nav的一些基本需求进行设置

     1 - (instancetype)initWithRootViewController:(UIViewController *)rootViewController
     2 {
     3     if (self = [super initWithRootViewController:rootViewController]) {
     4         // 设置navigationBar的背景颜色,根据需要自己设置
     5         self.navigationBar.barTintColor = redButtonColor;
     6         // 设置navigationBar是否透明,不透明的话会使可用界面原点下移(0,0)点为导航栏左下角下方的那个点
     7         self.navigationBar.translucent = NO;
     8         // 设置navigationBar是不是使用系统默认返回,默认为YES
     9         self.interactivePopGestureRecognizer.enabled = YES;
    10         // 创建一个颜色,便于之后设置颜色使用
    11         UIColor * color = [UIColor whiteColor];
    12         // 设置navigationBar元素的背景颜色,不包括title
    13         self.navigationBar.tintColor = color;
    14         // 设置navigationController的title的字体颜色
    15         NSDictionary * dict=[NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];
    16         self.navigationBar.titleTextAttributes = dict;
    17     }
    18     
    19     return self;
    20 }

    因为这个导航栏是你自己自定义的,所以默认的侧滑返回会失效,接下来要在viewDidLoad中从新遵循手势的代理

    - (void)viewDidLoad
    {
        // 为self创建弱引用对象
        __weak typeof (self) weakSelf = self;
        if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.interactivePopGestureRecognizer.delegate = weakSelf;
        }
    }

    OK,完成

  • 相关阅读:
    PAT A1094 The Largest Generation (25 分)——树的bfs遍历
    PAT A1055 The World's Richest (25 分)——排序
    PAT A1052 Linked List Sorting (25 分)——链表,排序
    PAT A1076 Forwards on Weibo (30 分)——图的bfs
    辅导员
    辅导员面试
    C程序设计
    Excel VBA 基本概念
    Excel函数
    导入excel表的数据到数据库ssh
  • 原文地址:https://www.cnblogs.com/LureBlog/p/4331907.html
Copyright © 2011-2022 走看看