GithubHelp home page GithubHelp logo

popevent's Introduction

PopEvent

English | 中文版

An elegant way to handling pop gesture recogenizer event.

Why PopEvent?

Have you ever had such a problem?

  • The screen-edge-pan gesture recognizer is invalid when you custom the leftNavigationItem.
  • When you want to make user confirm whether to popToSuperViewController or not, you should prevent the pop and present a `UIAlertController'.

Now you can implement them with a little bit of code.

Example

Enable ScreenEdgePan for 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

Prevent the pop

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];
}

Installation

CocoaPods

PopEvent is available through CocoaPods.

pod 'PopEvent'

Manual

Drag the PopEvent folder to your project.

Usage

PopEvent has two functions. First, #import "PopEvent.h".

Enable ScreenEdgePan for custom-backButton

Add only one line of code into -application: didFinishLaunchingWithOptions: in AppDelegate.

Make sure the code runs before the RootViewController's initialization when your app isn't loaded from storyboard.

[PopEvent restorePopGestureRecognizer];

Prevent the pop

Add only one line of code into the ViewController which will be prevented the pop gesture recognizer.

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

The first parameter need to be replaced by the event function name.

You can find detail in the Example.

Contribution

@talisk

Questions

Welcome to send email to me, or open issue on the repository.

The project follow to the MIT license. Welcome contributions.

popevent's People

Contributors

talisk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.