UIViewController不响应触摸 [英] UIViewController not responding to touches
问题描述
嘿,我完全被这个iPhone问题困扰住了.
Hey all, I'm completely stumped with this iPhone problem.
这是我第一次以编程方式构建视图,没有任何笔尖.我可以使视图显示的一切都很好,但是该织补ViewController并没有像我在使用笔尖的程序中那样响应触摸.我应该补充一点,过去我是从基于视图的应用程序模板开始的,而这次我使用的是基于窗口的应用程序模板.
This is my first time building a view programmatically, without a nib. I can get the view displaying things just fine, but the darn ViewController isn't responding to touches the way it used to in programs where I used a nib. I should add that in the past, I started with the View-Based Application template, and this time I used the Window-Based Application template.
我的想法是,基于视图的模板具有神奇的作用,可以使iPhone知道将触摸事件发送到哪里,但是即使经过数小时的Google讨论,我也无法弄清楚那是什么.否则我可能会在一个完全错误的地方寻找东西,而我的麻烦完全与其他事情有关.有什么想法吗?
My thinking is that the View-Based template does something magical to let the iPhone know where to send the touch events, but I can't figure out what that would be even after several hours of bumbling around Google. Or I could be looking in an entirely wrong place and my troubles are related to something else entirely. Any thoughts?
推荐答案
基于视图的模板中没有神奇的东西.无法响应触摸的最可能原因是:
There's nothing magical in the view-based template. The most likely reasons for failure to respond to touches are:
-
您已经弄乱了
touchesBegan:withEvent:
,userInteractionEnabled
,exclusiveTouch
或其他东西,以为您需要弄乱这些(通常您不会;默认设置通常是正确的)
You've messed with
touchesBegan:withEvent:
,userInteractionEnabled
,exclusiveTouch
or something else, thinking you need to mess with these (generally you don't; the defaults are generally correct)
您创建了第二个UIWindow
You created a second UIWindow
您在视图上放置了一些内容(即使它是透明的)
You put something over the view (even if it's transparent)
将您的代码简化为仅以编程方式创建一个对触摸做出响应的视图,而没有其他任何事情.它应该只是几行代码.如果您无法正常工作,请发布代码,然后我们会看看发生了什么.
Simplify your code down to just creating a view programatically that responds to a touch and nothing else. It should be just a few lines of code. If you can't get that working, post the code and we'll look at what's going on.
这篇关于UIViewController不响应触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!