程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-IOS多個UIView添加點擊

ios-IOS多個UIView添加點擊

編輯:編程綜合問答
IOS多個UIView添加點擊

剛剛接觸IOS開發,遇到以下問題想不通,希望高手給予指導。我給sendView、 payVIew、receiverView、 commentView設置點擊事件,為什麼
UITapGestureRecognizer * singleRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewClick:)];
singleRecognizer.numberOfTapsRequired = 1;
[self.sendView addGestureRecognizer:singleRecognizer];
[self.payVIew addGestureRecognizer:singleRecognizer];
[self.receiverView addGestureRecognizer:singleRecognizer];
[self.commentView addGestureRecognizer:singleRecognizer];
只有commentView能夠響應點擊事件,其他的三個UIView都無法響應點擊事件,但是我要是改成

UITapGestureRecognizer * singleRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewClick:)];
singleRecognizer.numberOfTapsRequired = 1;
[self.sendView addGestureRecognizer:singleRecognizer];

UITapGestureRecognizer * singleRecognizer1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewClick:)];
singleRecognizer1.numberOfTapsRequired = 1;
[self.payVIew addGestureRecognizer:singleRecognizer1];

UITapGestureRecognizer * singleRecognizer2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewClick:)];
singleRecognizer2.numberOfTapsRequired = 1;
[self.receiverView addGestureRecognizer:singleRecognizer2];

UITapGestureRecognizer * singleRecognizer3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewClick:)];
singleRecognizer3.numberOfTapsRequired = 1;
[self.commentView addGestureRecognizer:singleRecognizer3];
    就可以了呢?希望好心人能夠給我這個新手指點迷津

最佳回答:


第一種用法相當於創建了一個點擊手勢 給四個View賦值 它只可以賦值給一個對象 先給sendView賦值 一直執行代碼 最後賦值給了commentView,也就是前三個並沒有賦值上了,第二種寫法就是創建了4個點擊手勢分別給四個View賦值,就咩有問題了

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved