Custom Gesture Recognizer on iOS

61a68b2172503ecdf7a7f7757df56071?s=47 Tachibana Kaoru
April 27, 2020
430

Custom Gesture Recognizer on iOS

61a68b2172503ecdf7a7f7757df56071?s=128

Tachibana Kaoru

April 27, 2020
Tweet

Transcript

  1. 9.

    UITouch open class UITouch : NSObject { open var timestamp:

    TimeInterval { get } open var tapCount: Int { get } open var type: UITouch.TouchType { get } open func location(in view: UIView?) -> CGPoint open func previousLocation(in view: UIView?) -> CGPoint }
  2. 13.

    velocity vector with UITouch location previousLocation (x1 , y1 )

    (x2 , y2 ) ( x2 − x1 t2 − t1 , y2 − y1 t2 − t1 ) 2఺ؒͷ଎౓ϕΫτϧ
  3. 14.

    velocity vector with UITouch location previousLocation (x1 , y1 )

    (x2 , y2 ) ( x2 − x1 t2 − t1 , y2 − y1 t2 − t1 ) 2఺ؒͷ଎౓ϕΫτϧ (x2 − x1 , y2 − y1 ) 2఺ؒͷ୯Ґ࣌ؒ͋ͨΓͷ଎౓ϕΫτϧ
  4. 15.

    struct Velocity { var vx: CGFloat var vy: CGFloat }

    extension UITouch{ func velocity(in view: UIView?) -> Velocity{ let location = location(in: view) let previousLocation = previousLocation(in: view) let distanceX = location.x - previousLocation.x let distanceY = location.y - previousLocation.y let velocity = Velocity(vx: distanceX, vy: distanceY) return velocity }
  5. 19.

    gradient of UITouch location previousLocation (x1 , y1 ) (x2

    , y2 ) θ vx vy tan θ = vy vx θ = tan−1 vy vx
  6. 20.

    struct Velocity { var vx: CGFloat var vy: CGFloat var

    gradient: CGFloat{ // ࣮ࡍʹ͸ɺvyɺvx͕0ͷ࣌ͷॲཧ͓Αͼɺgradient஋͕ 0-2πʹͳΔΑ͏ͳ // ਖ਼نԽΛߦ͍·͢ var calcGradient = atan(vy / vx) return calcGradient }
  7. 27.

    UIGestureRecognizer.State open class UIGestureRecognizer : NSObject { // the current

    state of the gesture recognizer open var state: UIGestureRecognizer.State { get } }
  8. 28.

    class MyGestureRecognizer: UIGestureRecognizer{ override func touchesBegan(_ touches: Set<UITouch>, with event:

    UIEvent) { } override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) { } override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) { } override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent) { } override func reset() { } }
  9. 33.

    P F P P P P R F F touchesBegan

    touchesMoved touchesEnd
  10. 37.

    P F P P P P R F F touchesBegan

    touchesMoved touchesEnd
  11. 40.

    P F P P P F touchesBegan touchesMoved touchesEnd touchesEnd

    touchesMoved touchesMoved touchesBegan R F P P