IOS常用手势用法

target参数指的是给谁用手势,入button,view等

//1.单击

UITapGestureRecognizer *singleTapGR=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap:)];

[self.buttonView addGestureRecognizer:singleTapGR];

  - (void)singleTap:(UITapGestureRecognizer *)tap

  {

  NSLog(@"单击");

  }

//2.双击

UITapGestureRecognizer *doubleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];

doubleTap.numberOfTapsRequired=2;

[self.buttonView addGestureRecognizer:doubleTap];

//区别单击双击

[singleTapGR requireGestureRecognizerToFail:doubleTap];

//双击点击事件

-(void)doubleTap:(UITapGestureRecognizer *)taggestrue

{

NSLog(@"双击");

}

//3.轻扫

UISwipeGestureRecognizer *swipeGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];

//设置轻扫方向,默认向右

swipeGesture.direction=UISwipeGestureRecognizerDirectionDown;

[self.view addGestureRecognizer:swipeGesture];

  //轻扫事件

 -(void)swipe:(UISwipeGestureRecognizer *)swipeGesture

 {

 NSLog(@"轻扫手势");

 }

//4.平移

UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];

[self.view addGestureRecognizer:panGesture];

  -(void)pan:(UIPanGestureRecognizer *)pan

  {

  CGPoint point=[pan locationInView:self.view];

   NSLog(@"%@",NSStringFromCGPoint(point));

  }

//5.长按

UILongPressGestureRecognizer *longPressGesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];

longPressGesture.minimumPressDuration=1;

[self.buttonView addGestureRecognizer:longPressGesture];

  -(void)longPress:(UILongPressGestureRecognizer *)longPress

  {

  //长按离开时一会调用一次,所以需要设置手势状态

   if(longPress.state==UIGestureRecognizerStateEnded)

  {

  NSLog(@"UIGestureRecognizerStateEnded");

  return;

  }

  NSLog(@"长按超过两秒");

  }

时间: 2024-07-30 06:34:43

IOS常用手势用法的相关文章

iOS 常用手势

UIGestureRecognizer 对iOS的各种手势进行了封装,完全满足了用户对手势的需求. 以下是对各种手势的详细应用和说明,希望能对大家有帮助.^_^ - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor groupTableViewBackgroundColor]; _image

iOS常用手势识别器

手势识别状态: typedef NS_ENUM(NSInteger, UIGestureRecognizerState) { // 没有触摸事件发生,所有手势识别的默认状态 UIGestureRecognizerStatePossible, // 一个手势已经开始但尚未改变或者完成时 UIGestureRecognizerStateBegan, // 手势状态改变 UIGestureRecognizerStateChanged, // 手势完成 UIGestureRecognizerStateE

iOS中手势的delaysTouchesBegan属性用法(挖坑)

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/css/cuteeditor.css);iOS中手势的delaysTouchesBegan属性用法(挖坑),布布扣,bubuko.com

IOS开发—6种常用手势UIGestureRecognizer介绍

IOS 6种常用手势介绍 // // ViewController.m //  手势 // //  Created by Lotheve on 15/6/13. //  Copyright (c) 2015年Lotheve. All rights reserved. // #import "ViewController.h" @interface ViewController () { UITapGestureRecognizer *_tap;   //点击 UIPanGestureR

UI: UIGestureRecognizer IOS中手势的用法

UIGestureRecognizer 手势识别器,是常用手势的父类 可以手写代码,也可以拖拽应用手势. 1.触摸Touch 四个方法: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { _label1.text = @"触摸开始"; //1.获得触摸屏幕的手指 UITouch *touch = [touches anyObject]; //2.得到当前手指所在的位置的坐标 _startPoint = [

iOS 常用四种数据存储方式

iOS 常用四种数据存储方式 在iOS开发过程中,不管是做什么应用,都会碰到数据保存的问题.将数据保存到本地,能够让程序的运行更加流畅, ,使得用户体验更好.下面介绍?一下数据保存的方式: 1.NSKeyedArchiver:采用归档的形式来保存数据,该数据对象需要遵守NSCoding协议,并且该对象对应的类必须提供encodeWithCoder:和initWithCoder:方法.前?一个方法告诉系统怎么对对象进行编码,而后?一个方法则是告诉系统怎么对对象进行解码.例如对Possession对

ios的手势UIGestureRecognizer

一.概述 iPhone中处理触摸屏的操作,在3.2之前是主要使用的是由UIResponder而来的如下4种方式: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)

ios各种手势,很有意思

一.概述 iPhone中处理触摸屏的操作,在3.2之前是主要使用的是由UIResponder而来的如下4种方式: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event  - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent

ios的手势操作之UIGestureRecognizer

一.概述 iPhone中处理触摸屏的操作,在3.2之前是主要使用的是由UIResponder而来的如下4种方式: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)