How to Get users' touch operations in iOS
An iOS device is a multi-touch device that can be controlled by multiple fingers on the screen. So how can we get users' gesture operations in development? IOS has four finger operations: Press, lift, move, and cancel. The four methods are as follows:
// Press the screen and start to touch; override func touchesBegan (touches: Set
, WithEvent event: UIEvent) {println (touchesBegan)} // lift your finger and end the touch; override func touchesEnded (touches: Set
, WithEvent event: UIEvent) {println (touchesEnded)} // move your finger; override func touchesMoved (touches: Set
, WithEvent event: UIEvent) {println (touchesMoved)} // touch Cancel override func touchesCancelled (touches: Set
!, WithEvent event: UIEvent !) {Println (touchesCancelled )}
Then, test the touch operation by printing it on the console:
(1) press your finger: touchesBegan
(2) press your finger and lift it up: touchesBegan --> touchesEnded
(3) sliding fingers: touchesBegan --> touchesMoved --> touchesEnded
During the test, I did not find the touchesCancelled method called. At present, I do not know when to call this method. It will be used later. In the future, different responses can be made based on different user operations.