Several common gestures for uiimageview in iOS development

Source: Internet
Author: User

//

Viewcontroller.m

05- gestures

//

Created by Wanghy on 15/9/21.

Copyright (c) year Wanghy. All rights reserved.

//

#import "ViewController.h"

@interface viewcontroller ()

@property (weak, nonatomic) iboutlet uiimageview* imageView;

@end

@implementation Viewcontroller

-(void) viewdidload

{

[Super viewdidload];

additional setup after loading the view, typically from a nib.

//1. create an object for a gesture

//2. add the object of the gesture to the view that requires gestures

//3. ways to implement gestures

//uitapgesturerecognizer ( percussion )-------------

//// 1. objects that create gestures

//uitapgesturerecognizer* tap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (tap:)];

//// several fingers

//tap.numberoftouchesrequired = 2;

//// point a few times

//tap.numberoftapsrequired = 2;

//// 2. Adding gestures to ImageView

//[Self.imageview Addgesturerecognizer:tap];

//// 3. Implementation Method

//uiswipegesturerecognizer (swipe )-------------

//1.

Uiswipegesturerecognizer* swipe = [[uiswipegesturerecognizer alloc] initwithtarget :self action:@selector(swipe:)];

Uiswipegesturerecognizer* swipe1 = [[uiswipegesturerecognizer alloc] initwithtarget :self action:@selector(swipe:)];

// slide left

Swipe. direction = uiswipegesturerecognizerdirectionleft;

//2.

[self. ImageView addgesturerecognizer: swipe];

[self. ImageView addgesturerecognizer: swipe1];

//uilongpressgesturerecognizer ( Long press )-------------

//1.

Uilongpressgesturerecognizer* longpress = [[uilongpressgesturerecognizer alloc] Initwithtarget:self action:@selector(longpress:)];

// long-Press how long it takes to execute the method

Longpress. minimumpressduration = 2;

// error

Longpress. allowablemovement = ten;

//2.

[self. ImageView addgesturerecognizer: longpress];

//uirotationgesturerecognizer ( swivel )-------------

//1

Uirotationgesturerecognizer* rotation = [[uirotationgesturerecognizer alloc] Initwithtarget:self action:@selector(rotation:)];

//2.

[self. ImageView addgesturerecognizer: rotation];

//uipinchgesturerecognizer ( Pinch, for zooming )-------------

//1.

uipinchgesturerecognizer* pinch = [[uipinchgesturerecognizer alloc] initwithtarget :self action:@selector(pinch:)];

//2.

[self. ImageView Addgesturerecognizer:p inch];

//uipangesturerecognizer ( drag )-------------

//1.

uipangesturerecognizer* pan = [[uipangesturerecognizer alloc] initwithtarget: Self action:@selector(pan:)];

//2.

[self. ImageView Addgesturerecognizer:p an];

}

dragging

-(void) Pan: (uipangesturerecognizer*) sender

{

cgpoint p = [Sender translationinview:self. ImageView];

self. ImageView. Transform = cgaffinetransformtranslate(self. ImageView. Transform, p.x, p.y);

[Sender settranslation:cgpointzero inview:self. ImageView];

}

kneading

-(void) Pinch: (uipinchgesturerecognizer*) sender

{

//Self.imageView.transform = Cgaffinetransformmakescale (Sender.scale, sender.scale);

self. ImageView. Transform = Cgaffinetransformscale(self. ImageView. Transform, sender. Scale, sender. Scale);

Sender. scale = 1;

}

Rotate

-(void) Rotation: (uirotationgesturerecognizer*) sender

{

NSLog(@ "%f", sender. Rotation);

self. ImageView. Transform = cgaffinetransformrotate(self. ImageView. Transform, sender. Rotation);

Sender. rotation = 0;

//Self.imageView.transform = Cgaffinetransformmakerotation (sender.rotation);

}

Long Press

-(void) longpress: (uilongpressgesturerecognizer*) sender

{

// just want to start by executing a code that needs to determine the state of the gesture

if (sender. state = = Uigesturerecognizerstatebegan) {

NSLog(@ "longpress");

}

}

Swipe

-(void) Swipe: (uiswipegesturerecognizer*) sender

{

if (sender. Direction = = Uiswipegesturerecognizerdirectionleft) {

NSLog(@ "left");

}

else {

NSLog(@ "right");

}

}

percussion

-(void) Tap: (uitapgesturerecognizer*) sender

{

NSLog(@ "tap");

}

@end

Several common gestures for uiimageview in iOS development

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.