【问题标题】:Swift OS X NSTouch Phase rawInput to String?Swift OS X NSTouch Phase rawInput 到字符串?
【发布时间】:2017-08-03 01:54:43
【问题描述】:

似乎无法打印触摸阶段的字符串值 试过这个:

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)

【问题讨论】:

    标签: swift uitouch nstouch


    【解决方案1】:

    不是一个漂亮的方法:

    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)")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-01
      • 1970-01-01
      • 2016-02-13
      • 1970-01-01
      • 1970-01-01
      • 2013-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多