Introduction to Swift's class and method of clicking, double-clicking, pinching, rotating, dragging, scratching, and long gestures _swift

Source: Internet
Author: User

1.UITapGestureRecognizer Tap/Double-click gesture

Copy Code code as follows:

var tapgesture = UITapGestureRecognizer (target:self, Action: "Handletapgesture:")
Set the number of gestures to click: Click 2
tapgesture.numberoftapsrequired = 2
Self.view.addGestureRecognizer (Tapgesture)

2.UIPinchGestureRecognizer Pinch (zoom/shrink) gesture
Copy Code code as follows:

var pinchgesture = Uipinchgesturerecognizer (target:self, Action: "Handlepinchgesture:")
Self.view.addGestureRecognizer (Pinchgesture)

3.UIRotationGestureRecognizer Rotation gesture
Copy Code code as follows:

var rotategesture = Uirotationgesturerecognizer (target:self, Action: "Handlerotategesture:")
Self.view.addGestureRecognizer (Rotategesture)

4. Uipangesturerecognizer drag gesture
Copy Code code as follows:

var pangesture = Uipangesturerecognizer (target:self, Action: "Handlepangesture:")
Self.view.addGestureRecognizer (Pangesture)

5. Uiswipegesturerecognizer Motion Gesture
Copy Code code as follows:

var swipegesture = Uiswipegesturerecognizer (target:self, Action: "Handleswipegesture:")
Swipegesture.direction = uiswipegesturerecognizerdirection.left//No setting is right
Self.view.addGestureRecognizer (Swipegesture)

6. Uilongpressgesturerecognizer by gesture
Copy Code code as follows:

var longpressgesutre = Uilongpressgesturerecognizer (target:self, Action: "Handlelongpressgesture:")
Long time between
Longpressgesutre.minimumpressduration
The number of touches required
Longpressgesutre.numberoftouchesrequired
Self.view.addGestureRecognizer (Longpressgesutre)
The Uigesturerecognizerstate enumeration is defined as follows

Enum Uigesturerecognizerstate:int {

Case Possible//The recognizer has is not yet recognized its gesture, and but may is evaluating touch events. This is the default state

    Case began//the recognizer has received touches recognized as the gesture. The action method would Being called at the next turn of the run loop
    case Changed//The recognizer has received touches Gnized as a change to the gesture. The action method is called at the next turn on the run loop
    case Ended//the recognizer has Received touches recognized as the end of the gesture. The action method is called at the next turn the run loop and the recognizer would be reset to Uigesturerecognizers Tatepossible
    Case cancelled//the recognizer has received touches resulting in the cancellation of The gesture. The action method is called at the next turn the run loop. The recognizer is reset to uigesturerecognizerstatepossible

Case Failed//The recognizer has received a touch sequence which can not be recognized as the gesture. The action method is called and the recognizer is reset to uigesturerecognizerstatepossible
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.