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

  • 相关阅读:
    office2013 激活方式
    c# DataGridView绑定DataTable对象之后总会多一行
    oracle函数验证时间格式并返回
    Linux虚拟机与外面系统ping不通,或者连不上网
    恢复oracle中误删除drop掉的表
    WebService 检测到有潜在危险的 Request.Form 值
    mybatis标签之——关联映射
    word使用宏定义来统一设置图片大小
    mybatis常用标签
    mybatis标签之——<trim>
  • 原文地址:https://www.cnblogs.com/LureBlog/p/4331907.html
Copyright © 2020-2023  润新知