2012-09-24 18 views
0

我已經使用DCRoundSwitch來創建自定義開關,問題是我無法調用UIControlEventTouchUpInside事件,但只有UIControlEventValueChanged事件正在調用。無法調用DCRoundSwitch UIControlEventTouchUpInside事件

下面是我的代碼寫的viewDidLoad中:

self.swtchDailyReminder.on = YES; 
self.swtchDailyReminder.onTintColor =[UIColor colorWithRed:47.0/255.0 green:160.0/255.0 
blue:158.0/255.0 alpha:1.0]; 
[self.swtchDailyReminder addTarget:self action:@selector(switchDailyReminderToggled:) 
forControlEvents:UIControlEventTouchUpInside]; 

在此先感謝。

回答

0

UIControlEventTouchUpInside消息發送由DCRoundSwitchtouchesEnded方法。因此,需要調用此方法才能讓交換機接收消息來觸發您的操作。這不會發生,因爲UIGestureRecognizer正在發送touchesCancelled - 當他們識別出他們的手勢時,他們會自動取消與其他視圖的接觸。如果您在創建UIGestureRecognizer時將此行爲關閉,並使用它們的cancelsTouchesInView屬性將其連接到交換機(在DCRoundSwitch的設置方法中),這將允許touchesEnded將它的UIControlEventTouchUpInside消息發送到您的交換機,以便可以觸發您的操作。

希望這會有所幫助。

//注意:如果您的目標動作要運行一些動畫,則需要對DCRoundSwitch進行一些更改以防止它阻止您的動畫。詳情請參閱this SO answer

相關問題