Uigesture Basic gestures

Source: Internet
Author: User

Here are the zoom gestures and pinch gestures:

Directly on the code:

1 #import "ViewController.h"2 3 @interfaceViewcontroller () <UIGestureRecognizerDelegate>4 5 @end6 7 @implementationViewcontroller8 9- (void) Viewdidload {Ten [Super Viewdidload]; One     //additional setup after loading the view, typically from a nib. A      -     //If you need to rotate and scale simultaneously we also need to implement a protocol uigesturerecognizerdelegate -      the      -UIImage *image = [UIImage imagenamed:@"2.jpg"]; -      -Uiimageview *imageview =[[Uiimageview alloc]init]; +Imageview.frame = CGRectMake ( -, $, -, -); -imageview.userinteractionenabled =YES; +Imageview.image =image; A [Self.view Addsubview:imageview]; at      -     //Add a zoom gesture (pinch gesture) -_pinges =[[Uipinchgesturerecognizer alloc]initwithtarget:self Action: @selector (pinchact:)]; -      - [ImageView addgesturerecognizer:_pinges]; -      in     //Create a rotation gesture -_rotges =[[Uirotationgesturerecognizer alloc]initwithtarget:self Action: @selector (rotges:)]; to      + [ImageView addgesturerecognizer:_rotges]; -      the     //set up the protocol agent *_pinges.Delegate=Self ; $_rotges.Delegate=Self ;Panax Notoginseng      - } the  +- (void) Pinchact: (Uipinchgesturerecognizer *) pin{ A     //get the monitor image view (i.e. the ImageView object above) theUiimageview *iview = (Uiimageview *) Pin.view; +     //matrix transformation Calculation and assignment of Image view Objects -     //transform represents the transformation of a graphic $     //Cgaffinetransformscale produces a new matrix by zooming in $     //P1 the original matrix -     //P2 Scale in X-direction -     //p3 scale in y direction theIview.transform =Cgaffinetransformscale (Iview.transform, Pin.scale, Pin.scale); -     Wuyi      the     //To return a scale value to a unit value -Pin.scale =1; Wu      - } About  $- (void) Rotges: (Uirotationgesturerecognizer *) rotges{ -      -     //Get rotated Objects -Uiimageview *iview = (Uiimageview *) Rotges.view; A     //Calculate rotation changes and assign values +Iview.transform =cgaffinetransformrotate (Iview.transform, rotges.rotation); the      -     //Select angle Clear 0; $Rotges.rotation =0; the      the      the } the //Implementing protocol Methods - //can I respond to two gestures at the same time in //if the return value is yes you can respond at the same time; the-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (Uigesturerecognizer *) othergesturerecognizer{ the      About     returnYES; the}

This makes it easy to zoom (pinch) and rotate the view.

Uigesture Basic gestures

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.