0
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchlocation = [touch locationInView:self.view];

如果我有四个不同的按钮,您如何知道用户何时触摸某个按钮以及触摸了多少次。

4

3 回答 3

1

我很喜欢 C#,所以如果我错了,请原谅我,但是当用户点击图像时,你不能只增加一个整数,那么如果你想知道点击量,你会看这个整数吗?

于 2013-06-05T06:40:48.333 回答
0

what you will have to do is take one integer in.h file then in .m file write touchesbegan method like below.

  - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
   CGPoint touchlocation = [touch locationInView:self.view];
  if([touch isKindOfClass:[UIImage class]])
  {
     myInt++;//your global integer....
  }
}

let me know it is working or not!!!

Happy Coding!!!!

于 2013-06-05T06:43:26.650 回答
0

试试用这个..

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event allTouches] anyObject];

    // ----------you can find using tag and first set button's tag in xib ------
    if(touch.view.tag == btnRed.tag)
    {
       redTouch++:
    }
}
于 2013-06-05T06:48:33.237 回答