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?
推荐答案
根据this answer,按钮变成了专注的观点,它得到了所有的触动.您必须使您的视图(在其中实现 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屋!