PopEvent 0.2.0

PopEvent 0.2.0

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最新发布2016年12月

talisk 维护。



PopEvent 0.2.0

英文 | 中文版

一种优雅地处理弹出手势识别事件的方式。

为什么使用 PopEvent?

你是否遇到过以下问题?

  • 当你自定义 leftNavigationItem 时,屏幕边缘滑动手势识别器无效。
  • 当你想要让用户确认是否要弹出至父视图控制器时,你应该阻止弹出并显示 `UIAlertController`。

现在你只需稍微修改一些代码就可以实现。

示例

启用 custom-backButton 的屏幕边缘滑动

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"

启用 custom-backButton 的屏幕边缘滑动

AppDelegate 中的 -application: didFinishLaunchingWithOptions: 中添加一行代码。

确保在您的应用未从 Storyboard 加载时,代码在 RootViewController 初始化之前运行。

[PopEvent restorePopGestureRecognizer];

阻止弹出

在需要阻止弹出手势识别器的 ViewController 中添加一行代码。

[self addPopEventSelectorString:@"popEvent" viewControllerNamed:NSStringFromClass([self class])];

第一个参数需要替换为事件函数名。

详情请查看示例。

贡献

@talisk

问题

欢迎发送邮件给我,或在仓库中打开问题。

本项目遵循 MIT 许可协议。欢迎贡献。