我有一個自定義開關觸摸事件
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
,有時不會?以及爲什麼結束和跟蹤的事件與觸摸但不是開始?
在此先感謝。