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

2022-12-23  本文已影响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
上一篇 下一篇

猜你喜欢

热点阅读