Last active
December 30, 2015 12:59
-
-
Save caindy/7833089 to your computer and use it in GitHub Desktop.
Found this solution on stackoverflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface BSIView : UIView | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "BSIView.h" | |
@implementation UIView (FindAndResignFirstResponder) | |
- (BOOL)findAndResignFirstResponder | |
{ | |
if (self.isFirstResponder) { | |
[self resignFirstResponder]; | |
return YES; | |
} | |
for (UIView *subView in self.subviews) { | |
if ([subView findAndResignFirstResponder]) | |
return YES; | |
} | |
return NO; | |
} | |
@end | |
@implementation BSIView | |
- (id)initWithFrame:(CGRect)frame | |
{ | |
self = [super initWithFrame:frame]; | |
if (self) { | |
// Initialization code | |
} | |
return self; | |
} | |
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event | |
{ | |
UIView* hit = [super hitTest:point withEvent:event]; | |
if(!hit.isFirstResponder) | |
[self findAndResignFirstResponder]; | |
return hit; | |
} | |
/* | |
// Only override drawRect: if you perform custom drawing. | |
// An empty implementation adversely affects performance during animation. | |
- (void)drawRect:(CGRect)rect | |
{ | |
// Drawing code | |
} | |
*/ | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This may prove simpler, but I haven't tried it.
http://stackoverflow.com/a/12108918