当我点击视图时,它会增加该视图中的所有按钮计数,如果我点击一个按钮,它会增加该按钮数或任何其他按钮。我如何改变这一点,如果我点击按钮它会增加它的数量,当我点击视图中的任何地方时,它会增加所有其他按钮数。
- (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);
}
}
答案 0 :(得分:0)
如果您不希望视图触摸重新识别,则不需要触摸识别器。
对于按钮,使用IBAction
设置UIControlStateTouchUpInside
。单击按钮时,事件将被执行并且会增加计数