ios - UIGestureRecognizerState.Cancelled vs UIGestureRecognizerState.Failed -


what difference between .cancelled , .failed states?

how setting gesture recognizer's state .cancelled or .failed affect gesture recognizer itself?

when gesture recognizer's state become .cancelled , .failed?

at point gesture recognizer marked 'recognized'? after transition .began?

when yes, can gesture's state set .began in touchesmoved also?

for example @ stage pinching gesture recognized uipinchgesturerecognizer? guess in touchesmoved because pinching continuos gesture.

actually there no difference between .cancelled , .failed states. both leading gesture recognizer failing handle gesture. guess naming convention.

though, difference how both states affect gesture handling.

it depends of previous state of gesture recognizer was.

  1. if gesture recognizer transitioned .possible .began in touchesbegan(touches: set<uitouch>, withevent event: uievent) (uitouchphase.began phase of touch), in same method .failed or .cancelled, next gesture recognizer in queue(attached view) have opportunity handle gesture. no action message send.
  2. but if gesture recognizer transitioned .possible .began in touchesbegan(touches: set<uitouch>, withevent event: uievent) (uitouchphase.began phase of touch), in touchesmoved(touches: set<uitouch>, withevent event: uievent) method .failed or .cancelled gesture recognition fail , nothing happen. action message send anyway.
  3. if comment out code on line 8, gesture recognition fail , next gesture recognizer attached view have opportunity handle gesture.

so here view controller:

class viewcontroller: uiviewcontroller {      func panhandler(sender: uipangesturerecognizer) {          print("panhandler")     }      override func viewdidload() {         super.viewdidload()         // additional setup after loading view, typically nib.          let customrecognizer = customgesturerecognizer(target: self, action: #selector(viewcontroller.customhandler(_:)))         view.addgesturerecognizer(customrecognizer)          let panrecognizer = uipangesturerecognizer(target: self, action: #selector(viewcontroller.panhandler(_:)))         view.addgesturerecognizer(panrecognizer)      }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }      func customhandler(c: customgesturerecognizer) {         print("customhandler")     } } 

and here custom gesture recognizer:

import uikit import uikit.uigesturerecognizersubclass  class customgesturerecognizer: uigesturerecognizer {      override func touchesbegan(touches: set<uitouch>, withevent event: uievent) {         super.touchesbegan(touches, withevent: event)         state = .began         if touches.count == 1 {             //state = .failed         }         print("customgesturerecognizer.touchesbegan")     }      override func touchesmoved(touches: set<uitouch>, withevent event: uievent) {         super.touchesmoved(touches, withevent: event)          if state == .failed {             return         }          if touches.count == 1 {             state = .failed //.cancelled         }          state = .changed         print("customgesturerecognizer.touchesmoved")     }      override func touchesended(touches: set<uitouch>, withevent event: uievent) {         super.touchesended(touches, withevent: event)         state = .ended         print("customgesturerecognizer.touchesended")     } } 

just comment/uncomment code on lines 8, 10 , 23 see differences.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -