码迷,mamicode.com
首页 > 其他好文 > 详细

navigationcontroller手势翻页和navigationbar

时间:2015-06-18 09:26:07      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:

一. 系统导航默认手势

#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

 

navigationcontroller手势翻页和navigationbar

标签:

原文地址:http://www.cnblogs.com/apem/p/4584936.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!