Use of gestures in swift

Source: Internet
Author: User

/** Click Gesture */func Tapgesturedemo () {//build gesture recognizer let gesture = UITapGestureRecognizer (target:self, Action: "Viewtap:") Attach recognizer to view Self.view1.addGestureRecognizer (gesture)}/** zoom gesture */func Pinchgesturedemo () {//build gesture recognizer let gesture = U Ipinchgesturerecognizer (Target:self, Action: "Viewpinch:")//additional recognizer to view Self.view1.addGestureRecognizer (gesture)}/** Rotation gesture */func Rotationgesturedemo () {//build gesture recognizer let gesture = Uirotationgesturerecognizer (target:self, Action: "Viewro  Tation: ")//Add recognizer to view Self.view1.addGestureRecognizer (gesture)}/** swipe gesture */func Swipegesturedemo () {//create gesture recognizer Let Gesture = Uiswipegesturerecognizer (target:self, Action: "Viewswipe:")//additional recognizer to view Self.view1.addGestureRecognizer (g esture)}/** pan gesture */func Pangesturedemo () {//build gesture recognizer let gesture = Uipangesturerecognizer (target:self, Action: "VIEWP  AN: ")//Add recognizer to view Self.view1.addGestureRecognizer (gesture)}/** long press gesture */func Longpressgesturedemo () {//create gesture recognizer Let Gesture = UilongpressgesTurerecognizer (Target:self, Action: "Viewlongpress:")//additional recognizer to view Self.view1.addGestureRecognizer (gesture)}/** custom gestures    */func Custongesturedemo () {//build gesture recognizer let gesture = Customgesturerecognizer (target:self, Action: "Viewcustom:") Additional recognizers to view Self.view1.addGestureRecognizer (gesture)}//----------------------- Gesture Action Event---------------------------/** Click event */@IBAction func Viewtap (sender:uitapgesturerecognizer) {print (" Clicked ... ")}/** Scaling event */func viewpinch (sender:uipinchgesturerecognizer) {print (" pinch ... ") Let _width = View1.bounds . width let _height = view1.bounds.height view1.bounds.size = cgsize (width: _width * sender.scale, Height: _height * Sender.scale)}/** Rotation event */func viewrotation (sender:uirotationgesturerecognizer) {view1.transform = Cgaffinetransformmakerotation (sender.rotation)}/** sliding event */var offsetx:cgfloat = 0func viewswipe (sender:  Uiswipegesturerecognizer) {if sender.direction = = uiswipegesturerecognizerdirection.right {//Translate right 20 each time      OffsetX + = View1.transform = cgaffinetransformmaketranslation (OffsetX, 0)}}/** translation event */func Viewpan (Sende R:uipangesturerecognizer) {Let _transx = Sender.translationinview (view1). x Let _transy = Sender.translationinview ( view1). Y View1.transform = cgaffinetransformmaketranslation (_TRANSX, _transy)}/** Long press event */func viewlongpress (sender: Uilongpressgesturerecognizer) {print ("long pressed ...")}func Viewcustom (sender:customgesturerecognizer) {print (" Custom gesture ... ")}

  

Use of gestures in swift

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.