Skip to content

Instantly share code, notes, and snippets.

@huobazi
Created December 9, 2011 06:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save huobazi/1450404 to your computer and use it in GitHub Desktop.
Save huobazi/1450404 to your computer and use it in GitHub Desktop.
iOS 点击背景自动隐藏键盘
#import <UIKit/UIKit.h>
@interface UITextField (HideKeyBoard)
-(void)hideKeyBoard:(UIView *)view;
@end
#import "UITextField+HideKeyBoard.h"
@implementation UITextField (HideKeyBoard)
- (void) hideKeyBoard:(UIView*)view{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(doHideKeyBoard)];
tap.numberOfTapsRequired = 1;
[view addGestureRecognizer: tap];
[tap setCancelsTouchesInView:NO];
[tap release];
}
- (void)doHideKeyBoard{
[self resignFirstResponder];
}
@end
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.txtValue hideKeyBoard:self.view];
}
@meadlai
Copy link

meadlai commented Sep 7, 2012

[self.fm_username hideKeyBoard:self.view];

[self.fm_password hideKeyBoard:self.view];

当使用两次以后,只有最后一次生效,前面的都是无效的.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment