iOS开发iOS

iOS收起键盘的三种方法

2018-04-26  本文已影响0人  GodLiekZ

在UIViewController中收起键盘,除了调用相应控件的resignFirstResponder。例:

  - (BOOL)textFieldShouldReturn:(UITextField *)textField{

    if (![self.textField isExclusiveTouch]) {
        [self.textField resignFirstResponder];
    }
    return YES;
} 

还有另外的三种方法:

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

    [self.view endEditing:YES];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

     [[UIApplication sharedApplication]sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
}
上一篇 下一篇

猜你喜欢

热点阅读