Day.03.16 UITapGestureRecognizer 手勢(shì)識(shí)別器 ??????

ViewController.m

#import "ViewController.h"

@interface ViewController ()<UIGestureRecognizerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.userInteractionEnabled = YES;
    
    self.view.multipleTouchEnabled = YES;
    
//    [self tapGesture];
//    [self longPress];
//    [self swipeGesture];
//    [self panGesture];
    [self pinchGesture];
    
    
    
}

#pragma mark -- 點(diǎn)擊Tap
- (void)tapGesture{

//1.創(chuàng)建
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];

//2.屬性
    //點(diǎn)擊次數(shù)
    tap.numberOfTapsRequired =1;
    
    //手指?jìng)€(gè)數(shù)
    tap.numberOfTouchesRequired =1;
    
//3.添加手勢(shì)
    [self.view addGestureRecognizer:tap];
    
/*——————————————————————————————————————————————————————————————————————————————-*/
    UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    
    doubleTap.numberOfTapsRequired =2;
    
    [self.view addGestureRecognizer:doubleTap];
}

- (void)tapAction:(UITapGestureRecognizer *)tap{

    if (tap.numberOfTapsRequired == 1) {
        
        NSLog(@"single tap");
    }else if (tap.numberOfTapsRequired == 2){
    
        NSLog(@"double tap");
    }
}

#pragma mark -- 長按 longPress
- (void)longPress{

    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longAction:)];
    
    //設(shè)置長按時(shí)間
    longPress.minimumPressDuration = 3;
    
    [self.view addGestureRecognizer:longPress];
}

- (void)longAction:(UILongPressGestureRecognizer *)longPress{

    NSLog(@"long press");
    
    /**
     *  UIGestureRecognizerStatePossible,
     
     UIGestureRecognizerStateBegan,
     UIGestureRecognizerStateChanged,
     UIGestureRecognizerStateEnded,
     UIGestureRecognizerStateCancelled,
     UIGestureRecognizerStateFailed,
     UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded
     */
    NSLog(@"%ld",longPress.state);
}

#pragma mark --輕掃 swipe
- (void)swipeGesture{

    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
    
//設(shè)置輕掃方向
    swipe.direction = UISwipeGestureRecognizerDirectionRight;
    
    [self.view addGestureRecognizer:swipe];
}

- (void)swipeAction:(UISwipeGestureRecognizer *)swipe{

    NSLog(@"右輕掃");
}

#pragma mark --平移 pan
- (void)panGesture{

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
    
    [self.view addGestureRecognizer:pan];
}

- (void)panAction:(UIPanGestureRecognizer *)pan{

//獲取平移的坐標(biāo)點(diǎn)
    CGPoint p = [pan translationInView:self.view];
    
    NSLog(@"%@",NSStringFromCGPoint(p));
}

#pragma mark --捏合 pinch
- (void)pinchGesture{

    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
    
    [self.view addGestureRecognizer:pinch];
}

- (void)pinchAction:(UIPinchGestureRecognizer *)pinch{

    NSLog(@"%f",pinch.scale);
}

#pragma mark --旋轉(zhuǎn) rotation
- (void)rotationGesture{

    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
    
//設(shè)置代理
    rotation.delegate = self;
    
    [self.view addGestureRecognizer:rotation];
}

- (void)rotationAction:(UIRotationGestureRecognizer *)rotation{

    NSLog(@"%f",rotation.rotation);
}

#pragma mark --delegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{

    NSLog(@"手勢(shì)即將開始");
    
    return YES;
}

@end

屏幕快照 2016-03-16 下午7.57.15.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市礁叔,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌澄干,老刑警劉巖腾夯,帶你破解...
    沈念sama閱讀 216,843評(píng)論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件谐岁,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)伞访,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,538評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來轰驳,“玉大人厚掷,你說我怎么就攤上這事〖督猓” “怎么了冒黑?”我有些...
    開封第一講書人閱讀 163,187評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長勤哗。 經(jīng)常有香客問我抡爹,道長,這世上最難降的妖魔是什么芒划? 我笑而不...
    開封第一講書人閱讀 58,264評(píng)論 1 292
  • 正文 為了忘掉前任冬竟,我火速辦了婚禮,結(jié)果婚禮上民逼,老公的妹妹穿的比我還像新娘泵殴。我一直安慰自己,他們只是感情好拼苍,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,289評(píng)論 6 390
  • 文/花漫 我一把揭開白布笑诅。 她就那樣靜靜地躺著,像睡著了一般映屋。 火紅的嫁衣襯著肌膚如雪苟鸯。 梳的紋絲不亂的頭發(fā)上同蜻,一...
    開封第一講書人閱讀 51,231評(píng)論 1 299
  • 那天棚点,我揣著相機(jī)與錄音,去河邊找鬼湾蔓。 笑死瘫析,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的默责。 我是一名探鬼主播贬循,決...
    沈念sama閱讀 40,116評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼桃序!你這毒婦竟也來了杖虾?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,945評(píng)論 0 275
  • 序言:老撾萬榮一對(duì)情侶失蹤媒熊,失蹤者是張志新(化名)和其女友劉穎奇适,沒想到半個(gè)月后坟比,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,367評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡嚷往,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,581評(píng)論 2 333
  • 正文 我和宋清朗相戀三年葛账,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片皮仁。...
    茶點(diǎn)故事閱讀 39,754評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡籍琳,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出贷祈,到底是詐尸還是另有隱情趋急,我是刑警寧澤,帶...
    沈念sama閱讀 35,458評(píng)論 5 344
  • 正文 年R本政府宣布势誊,位于F島的核電站宣谈,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏键科。R本人自食惡果不足惜闻丑,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,068評(píng)論 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望勋颖。 院中可真熱鬧嗦嗡,春花似錦、人聲如沸饭玲。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,692評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽茄厘。三九已至矮冬,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間次哈,已是汗流浹背胎署。 一陣腳步聲響...
    開封第一講書人閱讀 32,842評(píng)論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留窑滞,地道東北人琼牧。 一個(gè)月前我還...
    沈念sama閱讀 47,797評(píng)論 2 369
  • 正文 我出身青樓,卻偏偏與公主長得像哀卫,于是被迫代替她去往敵國和親巨坊。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,654評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容