我有一个自定义开关触摸事件
UICustomSwtich
:UISlider
从here
下载它是如何工作
UICustomSwitch
覆盖此触摸事件,因为它必须工作:
- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
好测试
UICustomSwitch
完全在任何UIView
,甚至UIScrollView
。必须调用三个触摸事件才能正确调用。
坏作品
这里是我的问题。我有一个静态UITableView
从故事板设计的层次结构:
UITableView
>UITableViewCell
>UIView
>UICustomSwitch
在这种情况下:
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
此功能properlly称为
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
当我将拇指移动到小于条的长度时,拇指保持在我离开它的同一点(问题)。
当我将拇指向左和向右移动(上升条的末端)时,会调用两种方法(非常奇怪的行为,不是吗?)。
我寻找答案,找到不同解决方案的类似问题,但对我的问题有好处。
为什么触摸事件有时会达到我的UICustomSwitch
,有时不会?以及为什么结束和跟踪的事件与触摸但不是开始?
在此先感谢。