ScrollView 中TextField键盘隐藏

我们在UIScrollView中经常要使用UITextField或者别的文本编辑,通常我们需要点击空白处来隐藏键盘,这时你会发现在- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
这个方法中不能响应事件,这是因为UIScrollView截取了touch事件,我们需要声明个UIScrollView的Category,在里面重写


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; } 

通过super来把touch事件给传回父View。我们就可以在父View中处理响应事件了。

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