如何找出用户触摸图像的次数

时间:2013-06-05 06:38:08

标签: uibutton uitouch

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

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

3 个答案:

答案 0 :(得分:1)

我进入C#所以请原谅我,如果我错了,但是你不能只是在用户点击图片时增加一个整数,那么如果你想知道点击量,你会看到这整数?

答案 1 :(得分:0)

你需要做的是取一个整数in.h文件,然后在.m文件中写下touchesbegan方法,如下所示。

  - (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....
  }
}

让我知道它的工作与否!!!

快乐编码!!!!

答案 2 :(得分: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++:
    }
}
相关问题