gpt4 book ai didi

iOS 在位于 subview 中的 uitextfield 外部点击时隐藏键盘?

转载 作者:行者123 更新时间:2023-11-28 21:54:32 24 4
gpt4 key购买 nike

我是新手(而且我来自阿根廷,抱歉我的英语很基础),我真的不知道如何解决这个问题。我有一个 View ,其中包含一个用于 ScrollView 的 UIScrollView,并且在内部我有一个包含大量 UITextField 的 subview 。关键是当我在 UITextField 之外触摸时隐藏键盘,但我认为没有触发触摸事件(我不知道为什么,也许你可以帮助我)。我也是iOS的新手,但我正在学习!谢谢!

编辑:首先,感谢大家的回答!对于所有说要禁用 usar 交互的人来说,它适用于 UITextFields,但现在我无法与 UITable 的 subview 内部交互!有帮助吗?

最佳答案

试试这个

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

或者这个

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UIView * youtxtfl in self.view.subviews){
if ([youtxtfl isKindOfClass:[UITextField class]] && [youtxtfl isFirstResponder]) {
[youtxtfl resignFirstResponder];
}
}
}

关于iOS 在位于 subview 中的 uitextfield 外部点击时隐藏键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27038912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com