欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS常用几大手势的创建方法

程序员文章站 2022-04-11 15:07:01
常用几大手势的创建方法 /** * 手势: 1.点击手势 -- uitapgesturerecognizer 2.长按手势 -- uilongpressgesturer...

常用几大手势的创建方法

/**
 *  手势: 1.点击手势 -- uitapgesturerecognizer
         2.长按手势 -- uilongpressgesturerecognizer
         3.拖拉手势 -- uipangesturerecognizer
         4.捏合手势 -- uipinchgesturerecognizer
         5.轻扫手势 -- uiswipegesturerecognizer
         6.旋转手势 -- uirotationgesturerecognizer
 */

点击

// 1>. 点击手势 -- 创建
    uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(tap:)];

长按

// 2>. 长按手势
uilongpressgesturerecognizer *longpress = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(longclick:)];
// 设置手指个数 -- 模拟器上最大只能设置 2 个手指 ,真机可随便设置
longpress.numberoftouchesrequired = 1;
// 设置点击次数 -- 没有最大限制
// longpress.numberoftapsrequired = 2;
// 设置按上的时间
longpress.minimumpressduration = 3;

拖拉

// 3>. 拖拉手势
uipangesturerecognizer *pan = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(twolaclick:)];

捏合

// 4>. 捏合手势
uipinchgesturerecognizer *pinch = [[uipinchgesturerecognizer alloc] initwithtarget:self action:@selector(niehe:)];

轻扫

// 5>. 轻扫手势
uiswipegesturerecognizer *swipe = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(qingsao)];
// 设置手指的个数和
swipe.numberoftouchesrequired = 1;
// 设置轻扫方向
swipe.direction = uiswipegesturerecognizerdirectionright;

旋转

// 6>. 旋转手势
uirotationgesturerecognizer *rotation = [[uirotationgesturerecognizer alloc] initwithtarget:self action:@selector(xuanzhuan:)];

创建好手势后,添加到相应的view上,实现响应事件!!