問題描述
我有 2 個函數可以 resignFirstResponder,但是當文本字段在滾動視圖中時它們都不起作用
I have 2 functions to resignFirstResponder but neither of them works when the textfields are in scrollview
我的功能:
-(BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == textField1) {
[textField1 resignFirstResponder];
}
if (theTextField == textField2) {
[textField2 resignFirstResponder];
}
if (theTextField == textField3) {
[textField3 resignFirstResponder];
}
return YES;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
[textField1 resignFirstResponder];
[textField2 resignFirstResponder];
[textField3 resignFirstResponder];
}
我已經在 IB 中鏈接了滾動視圖,我不知道為什么只有當我在滾動視圖之外單擊時它才在那里不起作用.所以它只響應視圖,但是為什么?我認為 [[eventallTouches] anyObject]
響應 ANYObjects 處的 ALLtouches
I have linked the scroll view in IB, I can not find out why it does not works there only when I click outside of scrollview.so it only responds to view, but why?I thougth that [[event allTouches] anyObject]
respond to ALLtouches at ANYObjects
感謝您的幫助
推薦答案
增加一個透明的視圖,繼承 UIControl
的大小等于你的滾動視圖,不是更優雅一點嗎到它的最后面,然后為這個新視圖創建 IBAction
?
Wouldn't it be a bit more elegant to add a transparent view that inherits UIControl
with the size that equal to your scroll view to the very back of it and then just create IBAction
for this new view?
這篇關于UitextField resignFirstResponder 在滾動視圖中不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!