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,完成

  • 相关阅读:
    .net http大文件断点续传上传
    asp.net http大文件断点续传上传
    VUE http大文件断点续传上传
    JavaScript http大文件断点续传上传
    ceph之查看osd上pg的分布
    linux 文件系统
    Ceph对象存储网关中的索引工作原理<转>
    ceph 参数说明<转>
    iptables 配置
    c++ 回调类成员函数实现
  • 原文地址:https://www.cnblogs.com/LureBlog/p/4331907.html
Copyright © 2011-2022 走看看