IOS 改变系统导航栏自带的返回action事件
来源:互联网 发布:重复文件查找 知乎 编辑:程序博客网 时间:2024/05/16 17:09
#import <UIKit/UIKit.h>
@protocol BackButtonHandlerProtocol <NSObject>
@optional
// Override this method in UIViewController derived class to handle 'Back' button click
-(BOOL)navigationShouldPopOnBackButton;
@end
@interface UIViewController (BackButtonHandler) <BackButtonHandlerProtocol>
@end
#import "UIViewController+BackButtonHandler.h"
@implementation UIViewController (BackButtonHandler)
@end
@implementation UINavigationController (ShouldPopOnBackButton)
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem*)item {
if([self.viewControllers count] < [navigationBar.items count]) {
return YES;
}
BOOL shouldPop = YES;
UIViewController* vc = [self topViewController];
if([vc respondsToSelector:@selector(navigationShouldPopOnBackButton)]) {
shouldPop = [vc navigationShouldPopOnBackButton];
}
if(shouldPop) {
dispatch_async(dispatch_get_main_queue(), ^{
[self popViewControllerAnimated:YES];
});
} else {
// Workaround for iOS7.1. Thanks to @boliva - http://stackoverflow.com/posts/comments/34452906
for(UIView *subview in [navigationBar subviews]) {
if(subview.alpha < 1.) {
[UIView animateWithDuration:.25 animations:^{
subview.alpha = 1.;
}];
}
}
}
return NO;
}
@end
#import "ViewController.h"
#import "UIViewController+BackButtonHandler.h"
@implementation ViewController
-(void) viewDidLoad
{
[super viewDidLoad];
self.title = [NSString stringWithFormat:@"Screen-%d", self.navigationController.viewControllers.count];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain
target:selfaction:@selector(onNextBtn:)];
}
-(void) onNextBtn:(id)sender
{
[self.navigationController pushViewController:[ViewController new] animated:YES];
}
-(BOOL) navigationShouldPopOnBackButton ///在这个方法里写返回按钮的事件处理
{
[self.navigationController popViewControllerAnimated:YES];
return YES;
}
- IOS 改变系统导航栏自带的返回action事件
- 改变系统导航栏自带的返回按钮点击事件
- 改变iOS系统自带返回按钮事件
- 【导航】iOS自带的手势向左滑动返回
- 改变导航栏上面系统自己带的返回按钮及颜色
- 系统自带导航栏的注意事项
- iOS调用系统自带地图导航
- iOS中如何修改系统自带的导航栏的颜色
- IOS 改变导航栏返回按钮的标题
- IOS 改变导航栏返回按钮的标题
- iOS全局改变导航栏的返回按钮
- iOS 拦截系统自带的Pop事件
- IOS自定义系统导航栏:导航栏背景色、状态栏样式以及是否隐藏、拦截系统导航栏的返回点击事件
- IOS自定义系统导航栏:导航栏背景色、状态栏样式以及是否隐藏、拦截系统导航栏的返回点击事件
- 去掉webview自带导航栏 使用系统导航栏
- iOS 去除 导航栏的 自带 线条 (导航栏下面会有一条线 )
- iOS自带地图导航
- iOS花式更改系统自带UINavigationBar导航栏样式,让你拥有更纯净,更强自定义的导航栏!!!It's amazing
- Mysql Tomcat C3p0 系统性能调优个人总结
- 2014.4 阿里实习生招聘面试经历
- FZU Problem 2147 A-B Game (数学啊)
- Jersey注解详解
- 利用stl的集合类函数 操作mfc数组
- IOS 改变系统导航栏自带的返回action事件
- win7 安装matplotlib
- android 加载 动态库问题
- freemarker标签调用方法
- 开发模式和流程
- java quartz 中的时间格式 及启动定时器 触发器
- nyoj366 D的小L(STL)(DFS)
- nutch v1.9源码分析(4)——injector分析
- csdn查看朋友的会员资料博客页的字是没有内容可显示