UIImageView 的 UITextField 子视图不响应触摸事件
我有一个 UITextField,当它被添加为 self.view 的子视图时,它会响应触摸事件。当我将其添加为 UIImageView 的子视图时,它不再响应触摸事件。我将其设置为firstResponder,并且该字段处于活动状态并且仍然接受键盘输入。任何想法有什么问题吗?
I have a UITextField that responds to touch events when it is added as a subview of self.view. When I add it as a subview of a UIImageView it does not respond to touch events any more. I make it a firstResponder and the field is active and takes keyboard input still. Any ideas what is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UIImageView 文档状态:
尝试设置
imgView.userInteractionEnabled = YES
如果这不起作用,我会尝试在 UIView 中添加 UIImageView 和 UITextField 。无论如何,这种方法看起来更干净。
The docs for UIImageView state:
Try setting
imgView.userInteractionEnabled = YES
If this doesn't work, I would try adding the UIImageView and the UITextField in a UIView instead. Anyway, this approach seems cleaner.