【问题标题】:iPhone - Touch Area DetectioniPhone - 触控区域检测
【发布时间】:2012-09-24 04:51:03
【问题描述】:

我正在创建一个应用程序,允许用户在其中触摸线或路径上方。我想做一些事情,比如用户应该能够点击大约 20 像素的线。我用谷歌搜索了很多,但一无所获。

【问题讨论】:

  • 请更具体一些.....

标签: iphone objective-c ios xcode ipad


【解决方案1】:

以下是我的一个程序中的一段代码:在这里我做了类似的事情。用户在屏幕上点击的任何位置都会出现图像。我已将屏幕限制在某些区域,仅在其中注册点击。希望对你有帮助:!!

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {


  UITouch *touch = [[event allTouches] anyObject];
     CGPoint location = [touch locationInView:touch.view];
    image=[UIImage imageNamed:@"anyImage.gif"];
    newView = [[UIImageView alloc]initWithImage:image];
    if (location.y<117 || location.y>354)
    {
        newView.frame = CGRectMake (location.x, location.y,87,70);
        newView.center=location;
        [self addSubview:newView];

    }

    if (location.y<90)
    {
        if(location.y>85)
        {
            if (location.x>133 || location.x<183)
            {

                [self shakeA]; //A method shakeA is called

            }
        }
    }
    else if (location.y<360)
    {
        if (location.y>354)
        {
            if (location.x>133 || location.x<183)
            {       
                [self shakeB]; // Method shakeB called

            }
        }
    }
}

【讨论】:

  • 您的回答很有帮助。但我想检测图像周围的触摸。例如, if (point.x >= myimage's position) { // 做某事 }.
  • 只要找出你的myImage的坐标,然后用类似的逻辑在图像周围记录你的点击。!!
猜你喜欢
  • 1970-01-01
  • 2011-05-02
  • 2012-01-25
  • 2012-04-18
  • 2016-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多