英文 | 中文版
一种优雅地处理弹出手势识别事件的方式。
你是否遇到过以下问题?
leftNavigationItem
时,屏幕边缘滑动手势识别器无效。现在你只需稍微修改一些代码就可以实现。
AppDelegate.m
#import "AppDelegate.h"
#import "PopEvent.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[PopEvent restorePopGestureRecognizer];
return YES;
}
@end
ViewController1.m
#import "ViewController1.h"
#import "PopEvent.h"
@implementation ViewController1
- (void)viewDidLoad {
[super viewDidLoad];
[self addPopEventSelectorString:@"popEvent" viewControllerNamed:NSStringFromClass([self class])];
}
- (void)popEvent {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"PopEvent!" message:@"do something" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
}
将 PopEvent
文件夹拖放到您的项目中。
PopEvent 有两个功能。首先,#import "PopEvent.h"
。
在 AppDelegate
中的 -application: didFinishLaunchingWithOptions:
中添加一行代码。
确保在您的应用未从 Storyboard 加载时,代码在 RootViewController 初始化之前运行。
[PopEvent restorePopGestureRecognizer];
在需要阻止弹出手势识别器的 ViewController 中添加一行代码。
[self addPopEventSelectorString:@"popEvent" viewControllerNamed:NSStringFromClass([self class])];
第一个参数需要替换为事件函数名。
详情请查看示例。
欢迎发送邮件给我,或在仓库中打开问题。
本项目遵循 MIT 许可协议。欢迎贡献。