自定义可以侧滑返回的navigation
2015-11-18 18:40
316 查看
#import "NDNavigationController.h"
@interface NDNavigationController ()<UINavigationControllerDelegate, UIGestureRecognizerDelegate>
@property(nonatomic, weak) UIViewController *currentShowVC;
@end
@implementation NDNavigationController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController {
if (self = [super initWithRootViewController:rootViewController]) {
self.delegate = self;
self.interactivePopGestureRecognizer.delegate = self;
//
设置navigationBar的背景颜色,根据需要自己设置
self.navigationBar.barTintColor = kTabBarColor;
// 设置navigationBar是否透明,不透明的话会使可用界面原点下移(0,0)点为导航栏左下角下方的那个点
self.navigationBar.translucent = NO;
//
设置navigationBar是不是使用系统默认返回,默认为YES
self.interactivePopGestureRecognizer.enabled = YES;
//
设置navigationBar元素的背景颜色,不包括title
self.navigationBar.tintColor = KCommentColor;
//
设置navigationController的title的字体颜色
NSDictionary * dict=[NSDictionary dictionaryWithObject:kMainBlackColor forKey:NSForegroundColorAttributeName];
self.navigationBar.titleTextAttributes = dict;
//
统一替换 back item
的图片
UIImage * image = [UIImage imageNamed:@"com_navigatin_back_bt"];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[self.navigationBar setBackIndicatorImage:image];
[self.navigationBar setBackIndicatorTransitionMaskImage:image];
}
return self;
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (1 == navigationController.viewControllers.count) {
self.currentShowVC = nil;
} else {
self.currentShowVC = viewController;
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer == self.interactivePopGestureRecognizer) {
return (self.currentShowVC == self.topViewController);
}
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] &&
[otherGestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {
return YES;
} else {
return NO;
}
}
//解决:手指在滑动的时候,被 pop
的 ViewController
中的 UIScrollView 会跟着一起滚动
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return [gestureRecognizer isKindOfClass:UIScreenEdgePanGestureRecognizer.class];
}
@end
@interface NDNavigationController ()<UINavigationControllerDelegate, UIGestureRecognizerDelegate>
@property(nonatomic, weak) UIViewController *currentShowVC;
@end
@implementation NDNavigationController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController {
if (self = [super initWithRootViewController:rootViewController]) {
self.delegate = self;
self.interactivePopGestureRecognizer.delegate = self;
//
设置navigationBar的背景颜色,根据需要自己设置
self.navigationBar.barTintColor = kTabBarColor;
// 设置navigationBar是否透明,不透明的话会使可用界面原点下移(0,0)点为导航栏左下角下方的那个点
self.navigationBar.translucent = NO;
//
设置navigationBar是不是使用系统默认返回,默认为YES
self.interactivePopGestureRecognizer.enabled = YES;
//
设置navigationBar元素的背景颜色,不包括title
self.navigationBar.tintColor = KCommentColor;
//
设置navigationController的title的字体颜色
NSDictionary * dict=[NSDictionary dictionaryWithObject:kMainBlackColor forKey:NSForegroundColorAttributeName];
self.navigationBar.titleTextAttributes = dict;
//
统一替换 back item
的图片
UIImage * image = [UIImage imageNamed:@"com_navigatin_back_bt"];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[self.navigationBar setBackIndicatorImage:image];
[self.navigationBar setBackIndicatorTransitionMaskImage:image];
}
return self;
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (1 == navigationController.viewControllers.count) {
self.currentShowVC = nil;
} else {
self.currentShowVC = viewController;
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer == self.interactivePopGestureRecognizer) {
return (self.currentShowVC == self.topViewController);
}
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] &&
[otherGestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {
return YES;
} else {
return NO;
}
}
//解决:手指在滑动的时候,被 pop
的 ViewController
中的 UIScrollView 会跟着一起滚动
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return [gestureRecognizer isKindOfClass:UIScreenEdgePanGestureRecognizer.class];
}
@end
相关文章推荐
- JVM垃圾回收总结
- Codeforces Round #286 (Div. 1) D. Mr. Kitayuta's Colorful Graph (并查集 STL)
- 大型网站之分布式会话管理
- java读取目录下所有csv文件数据,存入三维数组并返回
- Android 屏幕适配方案
- 如何在github上寻找漏洞
- (java)Balanced Binary Tree
- 字符串加密
- MongoDB小结16 - find【查询条件$in】
- 计算机术语 blob
- (java)Power of Two
- tomcat源代码系列(三)--启动过程
- 给父母设计的一款手机
- haproxy安装配置介绍
- Android Studio中代码混淆
- android 设置textview中划线效果
- js常用事件总结
- js常用事件总结
- Activity回收时候fragment的异常
- Intel Threading Building Blocks 编程指南 : 内存分配