• navigationcontroller手势翻页和navigationbar


    一. 系统导航默认手势

    #import "CBNavigationController.h"
    
    //手势返回
    
    @interface CBNavigationController ()<UIGestureRecognizerDelegate, UINavigationControllerDelegate>
    
    @end
    
    @implementation CBNavigationController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        __weak CBNavigationController *weakSelf = self;
        
        if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
        {
            self.interactivePopGestureRecognizer.delegate = weakSelf;
            self.delegate = weakSelf;
            
        }
    }
    
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        
    }
    
    // Hijack the push method to disable the gesture
    
    //推进控制器
    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
        if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
            self.interactivePopGestureRecognizer.enabled = NO;
        
        [super pushViewController:viewController animated:animated];
    }
    
    //推出控制器
    - (UIViewController *)popViewControllerAnimated:(BOOL)animated
    {
        if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
            self.interactivePopGestureRecognizer.enabled = YES;
        return [super popViewControllerAnimated:animated];
    }
    
    #pragma mark UINavigationControllerDelegate
    
    //已经显示了控制器
    - (void)navigationController:(UINavigationController *)navigationController
           didShowViewController:(UIViewController *)viewController
                        animated:(BOOL)animate
    {
        //注意:这里当导航控制器只有一个viewcontroller的时候不能可以手势,否则奔溃
        if(self.viewControllers.count > 1) {
            if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
                self.interactivePopGestureRecognizer.enabled = YES;
        } else {
            if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
                self.interactivePopGestureRecognizer.enabled = NO;
        }
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end

    二. 导航栏的barStyle 和 translucent

    iOS7之后由于navigationBar.translucent默认是YES,坐标零点默认在(0,0)点  当不透明的时候,零点坐标在(0,64);如果你想设置成透明的,而且还要零点从(0,64)开始,那就添加:self.edgesForExtendedLayout = UIRectEdgeNone;

    translucent = NO, 零点从(0,64)开始, 如果想要零点从(0,0)点开始, 只需要设置: self.extendedLayoutIncludesOpaqueBars = YES;

    @property(nonatomic,assign) BOOL extendedLayoutIncludesOpaqueBars NS_AVAILABLE_IOS(7_0); // Defaults to NO, but bars are translucent by default on 7_0.  

    @property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets NS_AVAILABLE_IOS(7_0); // Defaults to YES

  • 相关阅读:
    Odometer使用JavaScript和CSS制作数字滑动效果
    50个必备的实用jQuery代码段
    优化移动体验的HTML5技巧
    20 个非常棒的jQuery内容滑动插件
    最全的js正则表达式用法大全
    大神都未必解决的了简单问题,关于文字左右两端对齐。
    盘点20款表现出众的HTML5游戏
    蓝桥杯 格子问题:输出同行同列同对角线格子的位置
    与曹学长的一番谈话
    21天学习活动之——我的讲课新体验
  • 原文地址:https://www.cnblogs.com/apem/p/4584936.html
Copyright © 2020-2023  润新知