嗨,我想獲得事件,當我觸摸已經選定的段。檢測事件時點擊已經選擇的片段
我已經實現了以下解決方案
import UIKit
class MARSSegmentController: UISegmentedControl {
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
}
*/
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
let oldValue:NSInteger = self.selectedSegmentIndex
super.touchesBegan(touches, withEvent: event)
if oldValue == self.selectedSegmentIndex{
sendActionsForControlEvents(UIControlEvents.ValueChanged)
}
}
}
這個工作正常,但ValueChanged事件得到,如果我攻非選擇分段執行兩次。
實施點按手勢不起作用。意味着當我點擊未選擇的片段時,它會在使用輕擊手勢時顯示舊的選定片段。
如果有任何解決方案,請提出建議。
請原諒我,如果我錯了,但我認爲這將觸摸下來,並觸及。 – Tobias
你可以先檢查UIEvent,如果它的值類型改變了,那麼不要調用sendActionsForControlEvents(UIControlEvents.ValueChanged) –