Deprecated, please use RxCocoa
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.
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
pod 'SHGestureRecognizerBlocks'
Put this either in specific files or your project prefix file
#import "UIGestureRecognizer+SHGestureRecognizerBlocks.h"
or
#import "SHGestureRecognizerBlocks.h"
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];
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];
-(void)SH_removeAllBlocks;
[tapGesture SH_removeAllBlocks];
@property(nonatomic,readonly) NSSet * SH_blocks;
for(SHGestureRecognizerBlock block in tapGesture.SH_blocks) {
}
Works fine with other gestures, such as swipe, pan and longpresses.
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(performBlockAction:)];
If you end up using SHGestureRecognizerBlocks in a project, I'd love to hear about it.
email: [email protected]
twitter: @seivanheidari
SHGestureRecognizerBlocks is © 2013 Seivan and may be freely
distributed under the MIT license.
See the LICENSE.md
file.