SHGestureRecognizerBlocks 1.1.1

SHGestureRecognizerBlocks 1.1.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Seivan Heidari.



  • By
  • Seivan Heidari

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(™)

Check the creating section

Create blocks directly from convenience class selectors

Add additional blocks on the gesture recognizer

Check the removing section

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

Check the properties section

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.