iOS笔记:经过hitTest:withEvent:隐藏键盘

目前最简单和直接的隐藏键盘的方法,经过覆盖hitTest:withEvent:方法并调用endEditing:方法来隐藏键盘。spa

先上代码code

@implementation ALXBackgroundView

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    UIView *view = [super hitTest:point withEvent:event];
    [view endEditing:YES];  //隐藏键盘
    return view;
}

@end

ALXBackgroundView直接继承自UIView,在您的代码中把UIViewController根view的实现类(UIView)直接替换为ALXBackgroundView类便可。继承

相关文章
相关标签/搜索