-1

ユーザーが線またはパスの上に触れることを許可するアプリを作成しています。ユーザーが線の約20ピクセルをタップできるようにするようなことをしたいと思います。私はたくさんグーグルで検索しましたが、何も見つかりませんでした。

4

1 に答える 1

1

以下は私のプログラムの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

            }
        }
    }
}
于 2012-09-24T04:54:41.957 に答える