LukasCZ / GSTouchesShowingWindow-Swift

Surface all touches in your iOS app when creating videos!
MIT License
379 stars 20 forks source link

Crash on shaking device #7

Open mpEsri opened 6 years ago

mpEsri commented 6 years ago

First, thanks for a very useful code.

I ran into an issue when shaking the device. It was due to unsafe unwrapping of the touches in the for statement: override public func sendEvent(_ event: UIEvent) { let touches = event.allTouches for touch in touches! { ...

I got around it by changing the code as shown below:

override public func sendEvent(_ event: UIEvent) {
    if let touches = event.allTouches {
        for touch in touches {
            switch touch.phase {
            case .began:
                self.controller.touchBegan(touch, view: self)

            case .moved:
                self.controller.touchMoved(touch, view: self)

            case .ended, .cancelled:
                self.controller.touchEnded(touch, view: self)

            default:
                break
            }
        }
    }

    super.sendEvent(event)
}