Six ways to use gestures

Source: Internet
Author: User
-(Void) viewdidload {[Super viewdidload]; // do any additional setup after loading the view. uiimageview * imageview = [[uiimageview alloc] initwithframe: cgrectmake (20, 30,280,430)]; imageview. image = [uiimage imagenamed: @ "2.jpg"]; // enable user interaction. Remember to enable interaction only between two uiimages and uilabel. [imageview setuserinteractionenabled: Yes]; [self. view addsubview: imageview]; [imageview release]; // use a gesture to view the inheritance relationship. Is there any initializer of your own? Method // 1. click uitapgesturerecognizer * tap = [[uitapgesturerecognizer alloc] initwithtarget: Self action: @ selector (tapaction :)]; // you can click this button several times to trigger the method tap. numberoftapsrequired = 3; // 1.2 you need several fingers to click the tap. numberoftouchesrequired = 2; // 1.3 Add the gesture to the imageview [imageview addgesturerecognizer: tap]; [tap release]; * // 2. long press uilongpressgesturerecognizer * longpress = [[uilongpressgesturerecognizer alloc] initwithtarget: Self action: @ selector (longpressaction :)]; // 1.1 the shortest time required for longpress. minimumpressduration = 3; // The longpress distance that allows the user's fingers to move in the long-pressed process. allowablemovement = 300; [imageview addgesturerecognizer: longpress]; [longpress release]; * // 3. rotate uirotationgesturerecognizer * rotation = [[uirotationgesturerecognizer alloc] initwithtarget: Self action: @ selector (rotationaction :)]; [imageview addgesturerecogni ZER: rotation]; [rotation release]; * // 4. kneading keys * pinch = [[uipinchgesturerecognizer alloc] initwithtarget: Self action: @ selector (pinchaction :)]; [imageview addgesturerecognizer: pinch]; [pinch release]; * // 5. drag uipangesturerecognizer * Pan = [[uipangesturerecognizer alloc] initwithtarget: Self action: @ selector (panaction :)]; [imageview addgesturerecognizer: Pan]; [Pan relea Se]; * // 6. cleaning direction * swipe = [[uiswipegesturerecognizer alloc] initwithtarget: Self action: @ selector (awipeaction :)]; [imageview addgesturerecognizer: Swipe]; // direction of cleaning, swipe. direction = uiswipegesturerecognizerdireleft; [swipe release];} // 6. cleaning-(void) awipeaction :( uiswipegesturerecognizer *) awipe {If (awipe. direction = uiswipegesturerecognizerdirele Ft) {nslog (@ "Left") ;}nslog (@ "clean") ;}// 5. drag-(void) panaction :( uipangesturerecognizer *) Pan {uiimageview * view = (uiimageview *) Pan. view; // obtain the point where the gesture passes through cgpoint P = [Pan translationinview: View]; // modify the view's transform attribute. transform = cgaffinetransformtranslate (view. transform, P. x, p. y); // initialize the drag position [Pan settranslation: cgpointzero inview: View]; // nslog (@ "drag");} // 4. pinch-(void) pinchaction :( uipinchgesturereco Gnizer *) pinch {// The attempted Tranform attribute uiimageview * view = (uiimageview *) pinch. view; // indicates the direction of X and Y. // view. transform = cgaffinetransformmakescale (pinch. scale, pinch. scale); // reset after kneading // pinch view on the original basis. transform = cgaffinetransformscale (view. transform, pinch. scale, pinch. scale); pinch. scale = 1; nslog (@ "kneading");} // 3. rotation-(void) rotationaction :( uirotationgesturerecognizer *) Rotation {// transform attribute of the view --- deformation // 1. get Adder Trend view uiimageview * imageview = (uiimageview *) rotation. view; // 2. rotation Angle (attribute, angle) imageview. transform = cgaffinetransformrotate (imageview. transform, rotation. rotation); rotation. rotation = 0; // nslog (@ "Rotate");} // 2. long press-(void) longpressaction :( uilongpressgesturerecognizer *) longpress {// The Long press method is triggered in each State of the gesture. Therefore, you need to make a judgment. // longpress. state if (longpress. state = uigesturerecognizerstatebegan) {nslog (@ "Long press to start oh !! ");} Else if (longpress. State = uigesturerecognizerstateended) {nslog (@" Long press ends !! ") ;}} // 1. Click the trigger method of the gesture-(void) tapaction :( uitapgesturerecognizer *) tap {nslog (@", that's a tower! ");}-(Void) didreceivemorywarning {[Super didreceivemorywarning]; // dispose of any resources that can be recreated .}


This article from the "Liu _ blog" blog, please be sure to keep this source http://liuyafang.blog.51cto.com/8837978/1548157

Six ways to use 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.