没有 UIControls 响应用户事件
我正在不使用 Interface Builder 创建一个 iOS 应用程序,并且我似乎缺少一些重要的东西,即我正在创建的控件(UITextField
、UIButton
等)没有响应触摸事件。
这是我的视图层次结构:
UIWindow->UIView->(UITextField, UIButton)
我能够创建上述层次结构,并且所有内容都在屏幕上正常显示,但点击 UITextField
或 UIButton
不会执行任何操作。我还尝试向 UIView
添加一些 UIGestureRecognizer
子类实例,但无济于事。
我可以在 UITextField
上调用 becomeFirstResponder
,并且应用程序会在键盘启动时启动并能够接收输入。然而,当键盘关闭时,界面将返回到“死”模式。
我缺少什么?
I am creating an iOS app without using Interface Builder and I seem to be missing something vital whereby the controls I am creating (UITextField
, UIButton
, etc.) are not responding to touch events.
Here's my view hierarchy:
UIWindow->UIView->(UITextField, UIButton)
I am able to create the above hierarchy and everything is showing up fine on the screen, but tapping on the UITextField
or the UIButton
do nothing. I also tried adding some UIGestureRecognizer
subclass instances to the UIView
to no avail.
I am able to call becomeFirstResponder
on the UITextField
and the application starts with the keyboard up and able to receive input. However when the keyboard is dismissed the interface goes back to its "dead" mode.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在
UIWindow
上调用init
,而不是initWithFrame:
。由于某种原因,一切都正确绘制,但UIWindow
没有响应事件,因为每次用户点击都超出了零大小窗口的范围。I was calling
init
on myUIWindow
instead ofinitWithFrame:
. For some reason everything was drawing correctly but theUIWindow
was not responding to events because every user tap was outside the bounds of the zero-size window.