refactor VoiceRecordButton's actions

This commit is contained in:
nixzhu
2015-08-05 12:27:49 +08:00
parent 67ceabd4a5
commit 0ff78f7d22
2 changed files with 16 additions and 27 deletions
@@ -151,20 +151,20 @@ class MessageToolbar: UIToolbar {
button.layer.borderColor = UIColor.messageToolBarHighlightColor().CGColor
button.tintColor = UIColor.messageToolBarHighlightColor()
button.yepTouchBegin = {
self.trySendVoiceMessageBegin()
button.touchesBegin = { [weak self] in
self?.trySendVoiceMessageBegin()
}
button.yepTouchesMoved = {
button.touchesMoved = {
}
button.yepTouchesEnded = {
self.trySendVoiceMessageEnd()
button.touchesEnded = { [weak self] in
self?.trySendVoiceMessageEnd()
}
button.yepTouchesCancelled = {
self.trySendVoiceMessageCancel()
button.touchesCancelled = { [weak self] in
self?.trySendVoiceMessageCancel()
}
return button
@@ -10,53 +10,42 @@ import UIKit
class VoiceRecordButton: UIView {
var yepTouchBegin : (() -> ())?
var touchesBegin : (() -> ())?
var yepTouchesEnded : (() -> ())?
var touchesEnded : (() -> ())?
var yepTouchesCancelled : (() -> ())?
var touchesCancelled : (() -> ())?
var yepTouchesMoved : (() -> ())?
var touchesMoved : (() -> ())?
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
if let yepTouchBegin = yepTouchBegin {
yepTouchBegin()
}
touchesBegin?()
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
if let yepTouchesEnded = yepTouchesEnded {
yepTouchesEnded()
}
touchesEnded?()
}
override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
if let yepTouchesCancelled = yepTouchesCancelled {
yepTouchesCancelled()
}
touchesCancelled?()
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesMoved(touches, withEvent: event)
if let yepTouchesMoved = yepTouchesMoved {
yepTouchesMoved()
}
touchesMoved?()
}
override func didMoveToSuperview() {
super.didMoveToSuperview()
makeUI()
makeUI()
}
private func makeUI() {