• 滑动返回


    #import "XMGNavigationViewController.h"
    
    @interface XMGNavigationViewController ()<UIGestureRecognizerDelegate>
    
    @end
    
    @implementation XMGNavigationViewController
    
    + (void)load
    {
        UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
        
        // 只要是通过模型设置,都是通过富文本设置
        // 设置导航条标题 => UINavigationBar
        NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
        attrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20];
        [navBar setTitleTextAttributes:attrs];
        
        // 设置导航条背景图片
        [navBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        // 控制手势什么时候触发,只有非根控制器才需要触发手势
        self.interactivePopGestureRecognizer.delegate = self;
        
        // 假死状态:程序还在运行,但是界面死了.
    }
    
    #pragma mark - UIGestureRecognizerDelegate
    // 决定是否触发手势
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
    {
        return self.childViewControllers.count > 1;
        
    }
    
    // <_UINavigationInteractiveTransition: 0x7f9c948302a0>:手势代理
    
    /*
     <UIScreenEdgePanGestureRecognizer: 0x7fdc4a740120; state = Possible; delaysTouchesBegan = YES; view = <UILayoutContainerView 0x7fdc4a73e690>; target= <(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition 0x7fdc4a740440>)>>
    
     */
    
    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
        if (self.childViewControllers.count > 0) { // 非根控制器
            
            // 恢复滑动返回功能 -> 分析:把系统的返回按钮覆盖 -> 1.手势失效(1.手势被清空 2.可能手势代理做了一些事情,导致手势失效)
            
            // 设置返回按钮,只有非根控制器
            viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem backItemWithimage:[UIImage imageNamed:@"navigationButtonReturn"] highImage:[UIImage imageNamed:@"navigationButtonReturnClick"]  target:self action:@selector(back) title:@"返回"];
    
        }
        
        // 真正在跳转
        [super pushViewController:viewController animated:animated];
        
    }
    
    - (void)back
    {
        [self popViewControllerAnimated:YES];
    }
    
    @end
  • 相关阅读:
    Jquery字符串,数组(拷贝、删选、合并等),each循环,阻止冒泡,ajax出错,$.grep筛选,$.param序列化,$.when
    Jquery cookie操作示例,写入cookie,读取cookie,删除cookie
    执行Sqlserver中waitfor delay延时操作或waitfor time定时操作
    JS里try...catch...finally详解,以及console日志调试(console.log、console.info等)
    19.Remove Nth Node From End of List---双指针
    18.4Sum
    16.3Sum Closest
    45.Jump Game II---贪心---2018大疆笔试题
    55.Jump Game---dp
    SQL相关
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/6503024.html
Copyright © 2020-2023  润新知