剛剛接觸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賦值,就咩有問題了