Use the IOS gesture uigesturerecognizer

Source: Internet
Author: User
The uikit contains the uigesturerecognizer class, which is used to detect gestures that occur on the device. Uigesturerecognizer is an abstract class that defines the basic behavior of all gestures. It has the following sub-classes used to process specific gestures: 1. Attach uitapgesturerecognizer (any number of hits) 2. Zoom in or out. 3. Shake or drag uipangesturerecognizer. 4. Touch uiswipegesturerecognizer. 5. Rotate uirotationgesturerecognizer) 6. uilongpressgesturerecognizer has different configuration attributes for different types of gesture identifiers. For example, uitapgesturerecognizer can configure the number of hits. After receiving a gesture, the interface can send a message to process the task after the gesture action is returned. Of course, different gesture identifiers send different message methods. The following code is a few examples: one finger, two-click gestures // create a gesture identification device uitapgesturerecognizer * onefingertwotaps = [[uitapgesturerecognizer alloc] initwithtarget: Self action: @ selector (onefingertwotaps)] autorelease]; // set required taps and number of touches [onefingertwotaps setnumberoftapsrequired: 2]; [onefingertwotaps limit: 1]; // Add the gesture to the view [[self view] addgesturerecognizer: onefingertwot APS]; message method onefingertwotaps-(void) onefingertwotaps {nslog (@ "Action: one finger, two taps");} two fingers, two-click Gesture Recognition * twofingerstwotaps = [[using alloc] initwithtarget: Self action: @ selector (listener)] autorelease]; [twofingerstwotaps failed: 2]; [using failed: 2]; [[self view] addgesturerecognizer: twofingerstwo Taps]; message method twofingerstwotaps-(void) twofingerstwotaps {nslog (@ "Action: two fingers, two taps ");} touch up and down with one finger. // touch up. * onefingerswipeup = [[delealloc] initwithtarget: Self action: @ selector (onefingerswipeup :)] autorelease]; [Response setction ction: uiswipegesturerecognizerdirectionup]; [[self view] addgesturerecognizer: onefingerswipeup];-(VO ID) onefingerswipeup :( uiswipegesturerecognizer *) recognizer {cgpoint point = [recognizer locationinview: [self view]; nslog (@ "swipe up-start location: % F, % F ", point. x, point. y);} // touch down * onefingerswipedown = [[delealloc] initwithtarget: Self action: @ selector (onefingerswipedown :)] autorelease]; [delesetction ction: callback Erdirectiondown]; [[self view] usage: onefingerswipedown];-(void) onefingerswipedown :( optional *) recognizer {cgpoint point = [recognizer locationinview: [self view]; nslog (@ "swipe down-start location: % F, % F", point. x, point. y);} rotation gesture uirotationgesturerecognizer * twofingersrotate = [[[uirotationgesturerecognizer alloc] initwithtarget: Self action: @ selector (twofinge Rsrotate :)] autorelzer]; [[self view] addgesturerecognizer: twofingersrotate];-(void) twofingersrotate :( uirotationgesturerecognizer *) recognizer {// convert the radian value to show the degree of rotation nslog (@ "rotation in degrees since last change: % F ", [recognizer rotation] * (180/m_pi);} The gesture uipinchgesturerecognizer * twofingerpinch = [[uipinchgesturerecognizer alloc] initwithtarg Et: Self action: @ selector (twofingerpinch :)] autorelch]; [[self view] addgesturerecognizer: twofingerpinch];-(void) twofingerpinch :( uipinchgesturerecognizer *) recognizer {nslog (@ "pinch scale: % F", recognizer. scale);} Forum original post address: http://www.cocoachina.com/bbs/read.php? Tid = 105316

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.