美文网首页
iOS拦截返回手势和返回按钮事件(支持iOS13之后)

iOS拦截返回手势和返回按钮事件(支持iOS13之后)

作者: 不要虚度美好的时光 | 来源:发表于2022-12-23 20:20 被阅读0次
#import "HZSHookVCBack.h"


- (BOOL)hzs_backGestureAction {
    NSLog(@"点击了返回按钮");
    [self showAlert];
    return NO;
}

- (BOOL)hzs_backBarButtonItemDidClickAction {
    NSLog(@"触发了返回手势");
    [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];
}

image.png

相关文章

网友评论

      本文标题:iOS拦截返回手势和返回按钮事件(支持iOS13之后)

      本文链接:https://www.haomeiwen.com/subject/jbtbqdtx.html