当我单击视图时,它会增加该视图中的所有按钮数,如果我单击一个按钮,它会增加该按钮数或任何其他按钮。我该如何更改它,所以如果我单击按钮它会增加它的计数,当我单击视图中的任何位置时它会增加所有其他按钮的计数。
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
[btnRed addGestureRecognizer:tapGestureRecognizer];
[btnYellow addGestureRecognizer:tapGestureRecognizer];
[btnGreen addGestureRecognizer:tapGestureRecognizer];
[btnBlue addGestureRecognizer:tapGestureRecognizer];
if (touch.view.tag == btnRed.tag)
{
redTouch++;
NSLog(@"%i",redTouch);
}
if (touch.view.tag == btnYellow.tag)
{
yellowTouch++;
NSLog(@"%i",yellowTouch);
}
if (touch.view.tag == btnGreen.tag)
{
greenTouch++;
NSLog(@"%i",greenTouch);
}
if (touch.view.tag==btnBlue.tag)
{
blueTouch++;
NSLog(@"%i",blueTouch);
}
}