UIButton阻止touchesBegan和touchesMoved [英] UIButton blocking touchesBegan and touchesMoved
问题描述
我正在为tvOS编写一个应用程序-直到我在屏幕上放置UIButton为止,所有这些都可以正常工作.添加按钮时,问题是touchesBegan和touchesMoved停止工作.如果我卸下按钮,那么touchesBegan和touchesMoved会再次开始正常工作.为了进行实验,我尝试取消选中启用用户交互"功能-但这没有任何区别.我还尝试了子类化UIButton并添加以下代码:
I'm writing an app for tvOS - and it all works until I put a UIButton on the screen. The problem, when buttons are added, is that touchesBegan and touchesMoved stop working. If I remove the buttons then touchesBegan and touchesMoved start working correctly again. I have tried, in the interests of experimentation, unchecking 'User Interaction Enabled' - but this didn't make any difference. I have also tried subclassing UIButton and adding the following code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[self.nextResponder touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
[self.nextResponder touchesMoved:touches withEvent:event];
}
可悲的是,这似乎也不起作用.有人对我下一步可以尝试的方法有什么建议吗?
Sadly this doesn't seem to work either. Does anyone have any suggestions as to what I might try next?
推荐答案
根据此答案,按钮变为集中的视图,它得到了所有的感动.您必须使视图(在其中实现touchesBegan
和touchesMoved
的视图)具有焦点.
According to this answer, the button becomes a focused view and it's getting all the touches. You have to make your view (in which you implement touchesBegan
and touchesMoved
) focusable.
这篇关于UIButton阻止touchesBegan和touchesMoved的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!