HZSHookVCBack
示例
导入头文件HZSHookVCBack.h,然后在ViewController中实现UINavigationControllerHookBackDelegate中的方法即可实现拦截。
- (BOOL)hzs_backGestureAction {
[self showAlert];
return NO;
}
- (BOOL)hzs_backBarButtonItemDidClickAction {
[self showAlert];
return NO;
}
- (void)showAlert {
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否要退出页面" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"确定退出" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self.navigationController popViewControllerAnimated:YES];
}]];
[self presentViewController:alert animated:YES completion:nil];
}
要求
安装
HZSHookVCBack可通过CocoaPods获取。要安装它,只需要将以下行添加到Podfile中
pod 'HZSHookVCBack'
作者
古德猫宁, [email protected]
许可协议
HZSHookVCBack遵循MIT许可协议。有关更多信息,请参阅LICENSE文件。