Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
iOS 点击背景自动隐藏键盘
#import <UIKit/UIKit.h>
@interface UITextField (HideKeyBoard)
-(void)hideKeyBoard:(UIView *)view;
#import "UITextField+HideKeyBoard.h"
@implementation UITextField (HideKeyBoard)
- (void) hideKeyBoard:(UIView*)view{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
tap.numberOfTapsRequired = 1;
[view addGestureRecognizer: tap];
[tap setCancelsTouchesInView:NO];
[tap release];
- (void)doHideKeyBoard{
[self resignFirstResponder];
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.txtValue hideKeyBoard:self.view];

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.