Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Prefixed UIGestureRecognizer category with blocks, auto-removed. Swizzle free!

License

Notifications You must be signed in to change notification settings

seivan-archives/SHGestureRecognizerBlocks

Repository files navigation

Deprecated, please use RxCocoa

SHGestureRecognizerBlocks

CI Status Version Platform License

This pod is used by SHUIKitBlocks as part of many components covering to plug the holes missing from Foundation, UIKit, CoreLocation, GameKit, MapKit and other aspects of an iOS application's architecture.

Overview

The gestures are automatically removed once their target is gone, so it isn't necessary to clean up - Swizzle Free(™)

Create blocks directly from convenience class selectors

Add additional blocks on the gesture recognizer

Remove specific blocks - will also remove the gesture recognizer from the target if it was the last block Remove all blocks - will also remove the gesture recognizer from the target

NSSet with all active blocks on the gesture

Installation

pod 'SHGestureRecognizerBlocks'

Setup

Put this either in specific files or your project prefix file

#import "UIGestureRecognizer+SHGestureRecognizerBlocks.h"

or

#import "SHGestureRecognizerBlocks.h"

Usage

Creating

With SHGestureRecognizerBlocks you can set auto-removed blocks instead of using selectors

  UITapGestureRecognizer * tapRecognizer = [UITapGestureRecognizer SH_gestureRecognizerWithBlock:^(UIGestureRecognizer *sender, UIGestureRecognizerState state, CGPoint location) {
    NSLog(@"callback");
  }];

  [self.view addGestureRecognizer:tapRecognizer];

or if you want add additional blocks

  UITapGestureRecognizer * tapRecognizer = [UITapGestureRecognizer alloc] init];

  SHGestureRecognizerBlock block = ^(UIGestureRecognizer *sender, UIGestureRecognizerState state, CGPoint location) {
    NSLog(@"CALLBACK block1");
  };


  SHGestureRecognizerBlock block2 = ^(UIGestureRecognizer *sender, UIGestureRecognizerState state, CGPoint location) {
    NSLog(@"CALLBACK block2");
  };

  [tapRecognizer SH_addBlock:block];
  [tapRecognizer SH_addBlock:block2];

  [self.view addGestureRecognizer:tapRecognizer];

Removing

Remove specific blocks - will also remove the gesture recognizer from the target if it was the last block

-(void)SH_removeBlock:(SHGestureRecognizerBlock)theBlock;

[tapGesture SH_removeBlock:block];

Remove all blocks - will also remove the gesture recognizer from the target

-(void)SH_removeAllBlocks;

[tapGesture SH_removeAllBlocks];

Properties

NSSet with all active blocks on the gesture

@property(nonatomic,readonly) NSSet * SH_blocks;

for(SHGestureRecognizerBlock block in tapGesture.SH_blocks) {
  
}

Existing Codebase

Works fine with other gestures, such as swipe, pan and longpresses.

Replacing

[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(performBlockAction:)];

Contact

If you end up using SHGestureRecognizerBlocks in a project, I'd love to hear about it.

email: [email protected]
twitter: @seivanheidari

License

SHGestureRecognizerBlocks is © 2013 Seivan and may be freely distributed under the MIT license. See the LICENSE.md file.

About

Prefixed UIGestureRecognizer category with blocks, auto-removed. Swizzle free!

Resources

License

Stars

Watchers

Forks

Packages

No packages published