UIImageView的UITextField子视图不响应触摸事件(UITextField subview of UIImageView is not responding to touch even

系统教程 行业动态 更新时间:2024-06-14 17:01:31
UIImageView的UITextField子视图不响应触摸事件(UITextField subview of UIImageView is not responding to touch events)

当它作为self.view的子视图添加时,我有一个UITextField,用于响应触摸事件。 当我将它作为UIImageView的子视图添加时,它不再响应触摸事件。 我使它成为第一个响应者,并且该字段处于活动状态,并且仍然需要键盘输入。 任何想法有什么不对?

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?

最满意答案

UIImageView状态的文档 :

新的图像视图对象被配置为默认忽略用户事件。 如果要处理UIImageView的自定义子类中的事件,则必须在初始化对象后明确将userInteractionEnabled属性的值更改为YES。

尝试设置imgView.userInteractionEnabled = YES

如果这不起作用,我会尝试在UIView中添加UIImageView和UITextField。 无论如何,这种方法似乎更清洁。

The docs for UIImageView state:

New image view objects are configured to disregard user events by default. If you want to handle events in a custom subclass of UIImageView, you must explicitly change the value of the userInteractionEnabled property to YES after initializing the object.

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.

更多推荐

本文发布于:2023-04-20 16:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/dbf12e1eda2772ffb2439c2f766f01d0.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   事件   UITextField   UIImageView   events

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!