隐藏键盘

//点击return

-(BOOL)textFieldShouldReturn:(UITextField *)textField

{

    [nameFieldresignFirstResponder];

    return YES;

}


//点击屏幕 键盘下去

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch=[[event allTouches] anyObject];

    if (touch.tapCount >=1) {

        [nameFieldresignFirstResponder];

    }

}


01 - (void)viewDidLoad
02 {
03     [super viewDidLoad];
04     // Do any additional setup after loading the view, typically from a nib.
05     UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
06     tapGr.cancelsTouchesInView = NO;
07     [self.view addGestureRecognizer:tapGr];
08 }
09 -(void)viewTapped:(UITapGestureRecognizer*)tapGr
10 {
11     [textfield resignFirstResponder];
12 }

你可能感兴趣的:(隐藏键盘)