class WatchShaker
{
public var delegate: WatchShakerDelegate?
fileprivate var motionManager: CMMotionManager!
fileprivate var lastShakeDate: Date?
!// The threshold for how much acceleration needs
to happen before an event will register.
fileprivate var threshold:Double
!// Time between shakes
fileprivate var delay:Double = 0.1
enum ShakeSensibility: Double {
case shakeSensibilitySoftest = 0.1
case shakeSensibilitySoft = 0.7
case shakeSensibilityNormal = 1.0
case shakeSensibilityHard = 1.2
case shakeSensibilityHardest = 2.0
}
guard let data = accelerometerData else {
let e = NSError(domain: "No accelerometer data", code: 666,
userInfo: ["No accelerometer data":"info"])
self.delegate?.watchShaker(self, didFailWith: e)
return
}
Slide 32
Slide 32 text
let valueX = fabs(data.acceleration.x)
let valueY = fabs(data.acceleration.y)
let maxValue = valueX > valueY ? valueX : valueY
if maxValue > self.threshold
{
if let lastDate = self.lastShakeDate
{
if Date().compare(lastDate.addingTimeInterval(self.delay))
!== .orderedDescending
{
self.lastShakeDate = Date()
self.delegate!?.watchShakerDidShake(self)
}
return
}
self.lastShakeDate = Date()
self.delegate!?.watchShakerDidShake(self)
}
Slide 33
Slide 33 text
:)
@ezefranca
Slide 34
Slide 34 text
No content
Slide 35
Slide 35 text
No content
Slide 36
Slide 36 text
3 vouchers para o curso
de SpriteKit
(100% em Swift ❤)