【发布时间】:2013-01-17 13:47:22
【问题描述】:
我有一个自定义开关
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。三个 touches 事件在需要调用的时候会正确调用。
坏作品
这是我的问题。我有一个从 StoryBoard 设计的静态UITableView,具有这种层次结构:
UITableView>UITableViewCell>UIView>UICustomSwitch
在这种情况下:
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
这个函数被正确调用
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
当我移动拇指小于条的长度时,拇指保持在我离开它的同一点(问题)。
当我左右移动拇指(上升到小节的末端)时,这两种方法被调用(非常奇怪的行为,不是吗?)。
我寻找答案,发现不同解决方案的类似问题,但对我的问题有任何好处。
为什么触摸事件有时会到达我的UICustomSwitch,有时却没有?以及为什么结束和 trackingWithTouch 事件而不是开始事件?
提前致谢。
【问题讨论】:
标签: ios cocoa-touch uitableview uitouch uicontrol