From 1bda5a84dc0303002bb3431061a4f94a04631900 Mon Sep 17 00:00:00 2001 From: Naoki Morita Date: Wed, 6 May 2015 22:47:30 +0900 Subject: [PATCH 1/4] Add basic log --- Pod/Classes/TouchVisualizer.swift | 34 ++++++++++++++++++++++--- Pod/Classes/TouchVisualizerConfig.swift | 20 ++++++++++----- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/Pod/Classes/TouchVisualizer.swift b/Pod/Classes/TouchVisualizer.swift index 10027a6..8d484f6 100644 --- a/Pod/Classes/TouchVisualizer.swift +++ b/Pod/Classes/TouchVisualizer.swift @@ -14,6 +14,8 @@ final public class TouchVisualizer { private var touchViews = [TouchView]() private var enabled:Bool = false + private var previousLog = "" + static let sharedInstance = TouchVisualizer() private init() { @@ -38,6 +40,7 @@ final public class TouchVisualizer { } // MARK: - Methods + public class func isEnabled() -> Bool { return sharedInstance.enabled } @@ -107,7 +110,6 @@ final public class TouchVisualizer { let keyWindow = UIApplication.sharedApplication().keyWindow! for touch in event.allTouches()! as! Set { - let phase = touch.phase switch phase { case .Began: @@ -117,22 +119,48 @@ final public class TouchVisualizer { view.beginTouch() view.center = touch.locationInView(keyWindow) keyWindow.addSubview(view) + log(touch) case .Moved: if let view = findTouchView(touch) { view.center = touch.locationInView(keyWindow) } + log(touch) case .Stationary: + log(touch) break case .Ended, .Cancelled: if let view = findTouchView(touch) { - UIView.animateWithDuration(0.2, delay: 0.0, options: .AllowUserInteraction, animations: { () -> Void in + UIView.animateWithDuration(0.2, delay: 0.0, options: .AllowUserInteraction, animations: { [unowned self] () -> Void in view.alpha = 0.0 view.endTouch() - }, completion: { (finished) -> Void in + }, completion: { [unowned self] (finished) -> Void in view.removeFromSuperview() + self.log(touch) }); } + log(touch) } } } + + public func log(touch: UITouch) { +// if !config.showsLog { +// return +// } + + var log = "" + var ti = 0 + for view in touchViews { + if view.superview != nil { + log += "[\(ti)] \(CGPoint(x: Int(view.center.x), y: Int(view.center.y)))\t" + ++ti + } + } + + if previousLog == log { + return + } + previousLog = log + println(log) + } } diff --git a/Pod/Classes/TouchVisualizerConfig.swift b/Pod/Classes/TouchVisualizerConfig.swift index 54d1b3d..525286b 100644 --- a/Pod/Classes/TouchVisualizerConfig.swift +++ b/Pod/Classes/TouchVisualizerConfig.swift @@ -47,6 +47,11 @@ public struct TouchVisualizerConfig { */ public var showsTouchRadius = false + /** + Shows log + */ + public var showsLog = false + public init() {} public mutating func setColor(color: UIColor) { self.color = color @@ -54,12 +59,6 @@ public struct TouchVisualizerConfig { public mutating func setImage(image: UIImage) { self.image = image } - public mutating func setShowsTimer(shows: Bool) { - self.showsTimer = shows - } - public mutating func setShowsTouchRadius(shows: Bool) { - self.showsTouchRadius = shows - } public mutating func setDefaultSize(size: CGSize) { var newSize = size if size.width != size.height { @@ -71,4 +70,13 @@ public struct TouchVisualizerConfig { } self.defaultSize = newSize } + public mutating func setShowsTimer(shows: Bool) { + self.showsTimer = shows + } + public mutating func setShowsTouchRadius(shows: Bool) { + self.showsTouchRadius = shows + } + public mutating func setShowsLog(shows: Bool) { + self.showsLog = shows + } } \ No newline at end of file From 55bd9009290609f31d681f8d0895ceb46a87cfff Mon Sep 17 00:00:00 2001 From: Naoki Morita Date: Wed, 6 May 2015 23:23:54 +0900 Subject: [PATCH 2/4] Add log method --- Pod/Classes/TouchVisualizer.swift | 34 +++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/Pod/Classes/TouchVisualizer.swift b/Pod/Classes/TouchVisualizer.swift index 8d484f6..068c68a 100644 --- a/Pod/Classes/TouchVisualizer.swift +++ b/Pod/Classes/TouchVisualizer.swift @@ -148,13 +148,43 @@ final public class TouchVisualizer { // return // } - var log = "" var ti = 0 + var viewLogs = [[String:String]]() for view in touchViews { + var index = "" if view.superview != nil { - log += "[\(ti)] \(CGPoint(x: Int(view.center.x), y: Int(view.center.y)))\t" + index = "\(ti)" ++ti } + + var phase = "" + switch touch.phase { + case .Began: phase = "B" + case .Moved: phase = "M" + case .Ended: phase = "E" + case .Cancelled: phase = "C" + case .Stationary: phase = "S" + } + + let x = String(format: "%.02f", Float(view.center.x)) + let y = String(format: "%.02f", Float(view.center.y)) + let center = "(\(x), \(y))" + + let radius = String(format: "%.02f", Float(touch.majorRadius)) + + viewLogs.append(["index": index, "center": center, "phase": phase, "radius": radius]) + } + + var log = "TV: " + for viewLog in viewLogs { + if count(viewLog["index"]!) == 0 { + continue + } + let index = viewLog["index"]! + let center = viewLog["center"]! + let phase = viewLog["phase"]! + let radius = viewLog["radius"]! + log += "[\(index)]<\(phase)> c:\(center) r:\(radius)\t" } if previousLog == log { From 56781dcf6cf929f6428335f33432d88e81186b60 Mon Sep 17 00:00:00 2001 From: Naoki Morita Date: Wed, 6 May 2015 23:28:06 +0900 Subject: [PATCH 3/4] Add Log change cell to Example ConfigViewController --- Example/Example/Base.lproj/Main.storyboard | 21 +++++++++++++++++++++ Example/Example/ConfigViewController.swift | 9 ++++++++- Pod/Classes/TouchVisualizer.swift | 6 +++--- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Example/Example/Base.lproj/Main.storyboard b/Example/Example/Base.lproj/Main.storyboard index 49816bf..22c7a63 100644 --- a/Example/Example/Base.lproj/Main.storyboard +++ b/Example/Example/Base.lproj/Main.storyboard @@ -55,6 +55,26 @@ + + + + + + + + + + @@ -126,6 +146,7 @@ + diff --git a/Example/Example/ConfigViewController.swift b/Example/Example/ConfigViewController.swift index 29ec476..c7612ef 100644 --- a/Example/Example/ConfigViewController.swift +++ b/Example/Example/ConfigViewController.swift @@ -13,6 +13,7 @@ final class ConfigViewController: UITableViewController { @IBOutlet weak var timerCell: UITableViewCell! @IBOutlet weak var touchRadiusCell: UITableViewCell! + @IBOutlet weak var logCell: UITableViewCell! @IBOutlet weak var blueColorCell: UITableViewCell! @IBOutlet weak var redColorCell: UITableViewCell! @@ -58,6 +59,9 @@ final class ConfigViewController: UITableViewController { } config.showsTouchRadius = !config.showsTouchRadius } + if cell == logCell { + config.showsLog = !config.showsLog + } if cell == blueColorCell { config.color = colors["blue"]! } @@ -73,7 +77,7 @@ final class ConfigViewController: UITableViewController { } func updateCells() { - let boolCells = [timerCell, touchRadiusCell] + let boolCells = [timerCell, touchRadiusCell, logCell] for cell in boolCells { cell.detailTextLabel?.text = "false" } @@ -88,6 +92,9 @@ final class ConfigViewController: UITableViewController { if config.showsTouchRadius { touchRadiusCell.detailTextLabel?.text = "true" } + if config.showsLog { + logCell.detailTextLabel?.text = "true" + } if config.color == colors["blue"] { blueColorCell.accessoryType = .Checkmark } diff --git a/Pod/Classes/TouchVisualizer.swift b/Pod/Classes/TouchVisualizer.swift index 068c68a..09498df 100644 --- a/Pod/Classes/TouchVisualizer.swift +++ b/Pod/Classes/TouchVisualizer.swift @@ -144,9 +144,9 @@ final public class TouchVisualizer { } public func log(touch: UITouch) { -// if !config.showsLog { -// return -// } + if !config.showsLog { + return + } var ti = 0 var viewLogs = [[String:String]]() From 2600a2c187eca5b687140e2f0e449367fc50b5b9 Mon Sep 17 00:00:00 2001 From: Naoki Morita Date: Wed, 6 May 2015 23:41:40 +0900 Subject: [PATCH 4/4] Remove unused mutable funcs in TouchVisualizerConfig --- Example/Example/AppDelegate.swift | 1 + Example/Example/Base.lproj/Main.storyboard | 2 +- Pod/Classes/TouchVisualizerConfig.swift | 28 +--------------------- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index 759efef..5e887eb 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -24,6 +24,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // config.color = UIColor.purpleColor() // config.showsTimer = true // config.showsTouchRadius = true +// config.showsLog = true // TouchVisualizer.start(config) return true diff --git a/Example/Example/Base.lproj/Main.storyboard b/Example/Example/Base.lproj/Main.storyboard index 22c7a63..dea16aa 100644 --- a/Example/Example/Base.lproj/Main.storyboard +++ b/Example/Example/Base.lproj/Main.storyboard @@ -60,7 +60,7 @@ -