手势识别器
一、?勢(shì)識(shí)別器
? ? ?是對(duì)觸摸事件做了封裝,我們?需??去判斷某個(gè)?勢(shì) 是否觸發(fā),?勢(shì)識(shí)別器本?起到了識(shí)別作?,我們把重?放在識(shí)別之 后要做什么操作上?。
二、 七種手勢(shì)識(shí)別器
? ?1,輕拍手勢(shì)識(shí)別器 ?UITapGestureRecognizer
? ?2,我們不會(huì)直接使??勢(shì)識(shí)別器這個(gè)抽象?類,?是根據(jù)需要使?特定的?勢(shì)識(shí)別器創(chuàng)建對(duì)象。
? ? ? ?1)、創(chuàng)建UITapGestureRecognizer對(duì)象,使?initWithTarget:action:?法;
? ? ? ?2)、配置要識(shí)別的?勢(shì)的相關(guān)信息;
? ? ? ?3)、將?勢(shì)添加到某個(gè)視圖上;
? ? ? ? ? ? ? 如:[imageView addGestureRecognizer:tap];
? ? ? ?4)、實(shí)現(xiàn)?勢(shì)識(shí)別器?定義的?法 ?
? ? ? ? ? ??獲取當(dāng)前手勢(shì)放在哪一個(gè)view上 ??tap.view
三、 創(chuàng)建旋轉(zhuǎn)手勢(shì)
? ? ??
??創(chuàng)建旋轉(zhuǎn)手勢(shì)
?
? ? UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(doRotation:)];
?
? ? [imageView addGestureRecognizer: rotation];
?
? ? rotation.delegate = self;
?
? ? [rotation release];
?
? 注意:
?// 在做旋轉(zhuǎn)的時(shí)候?qū)?yīng)兩個(gè)函數(shù),一個(gè)是CGAffineTransformRotate(連續(xù)旋轉(zhuǎn)),另一個(gè)是CGAffineTransformMakeRotation(做一次旋轉(zhuǎn))
? ? // 在上次的基礎(chǔ)上旋轉(zhuǎn)
? ? arotation.view.transform = CGAffineTransformRotate(arotation.view.transform, arotation.rotation);
?? ?
? ? // 讓旋轉(zhuǎn)角歸零,下次在新角度下旋轉(zhuǎn),而不是累加
? ? arotation.rotation = 0;
?
四、創(chuàng)建捏合手勢(shì)
? ?創(chuàng)建
?// 創(chuàng)建捏合手勢(shì)
? ? UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(doPinch:)];
? ? [imageView addGestureRecognizer:pinch];
? ? pinch.delegate = self;
? ? [pinch release];
注意:
??pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);
? ? pinch.scale = 1;// 在原對(duì)象的基礎(chǔ)上變化
?
轉(zhuǎn)載于:https://www.cnblogs.com/qiushifalife/p/4758980.html
新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎(jiǎng)!定制產(chǎn)品紅包拿不停!總結(jié)
- 上一篇: 系统磁盘空间满的一个问题
- 下一篇: pat Simulation Test