IOS開發之觸摸與點擊事件:UITapGestureRecognizer與UIPanGestureRecognizer應用

來源:互聯網
上載者:User

UITapGestureRecognizer與UIPanGestureRecognizer應用:    
一:UITapGestureRecognizer應用:


- (void)singleOne:(UITapGestureRecognizer *)sender { }//將相應事件發生時的動作寫入函數

- (void)singleTwo:(UITapGestureRecognizer *)sender { }

- (void)doubleOne:(UITapGestureRecognizer *)sender { }

- (void)doubleTwo:(UITapGestureRecognizer *)sender { }

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

singleOne.numberOfTouchesRequired = 1;  //觸摸點個數,另作:[singleOne setNumberOfTouchesRequired:1];

singleOne.numberOfTapsRequired = 1;  //點擊次數,另作:[singleOne setNumberOfTapsRequired:1];

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

singleTwo.numberOfTouchesRequired = 2; 

singleTwo.numberOfTapsRequired = 1; 

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

doubleOne.numberOfTouchesRequired = 1; 

doubleOne.numberOfTapsRequired = 2; 

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

doubleTwo.numberOfTouchesRequired = 2; 

doubleTwo.numberOfTapsRequired = 2;

[singleOne requireGestureRecognizerToFail:doubleOne]; //防止:雙擊被單擊攔截[singleTwo requireGestureRecognizerToFail:doubleTwo]; //防止:雙擊被單擊攔截

[self.view addGestureRecognizer:singleOne];  

[self.view addGestureRecognizer:singleTwo];

[self.view addGestureRecognizer:doubleOne];

[self.view addGestureRecognizer:doubleTwo];

[singleOne release];

[singleTwo release];

[doubleOne release];

[doubleTwo release];


UIPanGestureRecognizer後期分享


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.