2017-08-03 38 views
0

似乎無法打印觸摸階段的字符串值已經試過這樣:Swift OS X NSTouch階段rawInput到字符串?

let phase = NSTouch.Phase(rawValue: touch.phase.rawValue)    
print(phase) 

let touches = event.touches(matching: NSTouch.Phase.ended, in: self.view) 
touches.forEach { (touch) in 
    print(" touch up \(touch.phase)") 
} 

輸出我得到的是周圍這個

Phase(rawValue: 8) 
﹣ touch up Phase(rawValue: 8) 

回答

0

不漂亮的方式:

print("Began", String(describing: NSTouch.Phase.began)) 
print("Ended", String(describing: NSTouch.Phase.ended)) 
print("Moved", String(describing: NSTouch.Phase.moved)) 
print("Stationary", String(describing: NSTouch.Phase.stationary)) 
print("Touching", String(describing: NSTouch.Phase.touching)) 
print("Cancelled", String(describing: NSTouch.Phase.cancelled)) 

結果幫助生產這個:

let phases = [ 
      "1":"Began", 
      "2":"Moved", 
      "4":"Stationary", 
      "7":"Touching", 
      "8":"Ending", 
      "16":"Cancelled" 
] 

let phase = phases["\(touch.phase.rawValue)"] 
print(" Finger touch down \(phase)")