From 0ff78f7d2240d64b9e31ecddeb9056d55bd35a1e Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 5 Aug 2015 12:27:49 +0800 Subject: [PATCH] refactor VoiceRecordButton's actions --- Yep/Views/MessageToolbar/MessageToolbar.swift | 14 ++++----- .../MessageToolbar/VoiceRecordButton.swift | 29 ++++++------------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/Yep/Views/MessageToolbar/MessageToolbar.swift b/Yep/Views/MessageToolbar/MessageToolbar.swift index 4a112aee..d28483b8 100644 --- a/Yep/Views/MessageToolbar/MessageToolbar.swift +++ b/Yep/Views/MessageToolbar/MessageToolbar.swift @@ -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 diff --git a/Yep/Views/MessageToolbar/VoiceRecordButton.swift b/Yep/Views/MessageToolbar/VoiceRecordButton.swift index 6d6ee47d..38568134 100644 --- a/Yep/Views/MessageToolbar/VoiceRecordButton.swift +++ b/Yep/Views/MessageToolbar/VoiceRecordButton.swift @@ -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, withEvent event: UIEvent) { super.touchesBegan(touches, withEvent: event) - if let yepTouchBegin = yepTouchBegin { - yepTouchBegin() - } + touchesBegin?() } override func touchesEnded(touches: Set, withEvent event: UIEvent) { super.touchesEnded(touches, withEvent: event) - if let yepTouchesEnded = yepTouchesEnded { - yepTouchesEnded() - } + touchesEnded?() } override func touchesCancelled(touches: Set!, withEvent event: UIEvent!) { super.touchesCancelled(touches, withEvent: event) - if let yepTouchesCancelled = yepTouchesCancelled { - yepTouchesCancelled() - } + touchesCancelled?() } override func touchesMoved(touches: Set, withEvent event: UIEvent) { super.touchesMoved(touches, withEvent: event) - if let yepTouchesMoved = yepTouchesMoved { - yepTouchesMoved() - } + touchesMoved?() } - - override func didMoveToSuperview() { - super.didMoveToSuperview() - makeUI() + makeUI() } private func makeUI() {