0

みんな!同時に異なる画像ビューで 2 つのタッチを検出する必要があります。したがって、ユーザーが両方の画像ビューを同時にタッチしたときにタイマーを開始する必要があります。タッチが終了するとタイマーを停止します。画像ビューは画面上を移動しています。1 つのイメージ ビューを使用する場合は問題ありません。何かアイデアはありますか?

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

    NSSet *allTouches = [event allTouches];
    for (UITouch *touch in allTouches)
    for (UITouch *touch2 in allTouches)

    {
        CGPoint location = [touch locationInView:touch.view];
        CGPoint location2 = [touch2 locationInView:touch2.view];

        if ([touchArea2.layer.presentationLayer hitTest:location2]) {
             touchArea2.image = [UIImage imageNamed:@"TouchAreaTouched"];
        }
        if ([touchArea.layer.presentationLayer hitTest:location]) {
           touchArea.image = [UIImage imageNamed:@"TouchAreaTouched"];

            timerTouch = 10;
            touchTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(randomVoid) userInfo:nil repeats:YES];
        } else if (![touchArea.layer.presentationLayer hitTest:location]){
            [touchTimer invalidate];
            touchTimer = nil;
        } }
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSSet *allTouches = [event allTouches];
    for (UITouch *touch in allTouches)
        for (UITouch *touch2 in allTouches)   {


            CGPoint location = [touch locationInView:touch.view];
            CGPoint location2 = [touch2 locationInView:touch2.view];


            if (![touchArea.layer.presentationLayer hitTest:location]){
                touchArea2.image = [UIImage imageNamed:@"TouchArea"];
                touchArea.image = [UIImage imageNamed:@"TouchArea"];
                [touchTimer invalidate];
                touchTimer = nil;
            }
        }

}


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

    touchArea.image = [UIImage imageNamed:@"TouchArea"];
    [touchTimer invalidate];
}

助けてくれてありがとう))

4

4 に答える 4

1

UIGestureRecognizerDelegate次に、方法を確認することをお勧めします。

gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
于 2012-11-19T13:13:06.740 に答える
0

私はこの問題についてよく考え、それを行う方法を見つけました。これが私のコードです:

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

    NSSet *allTouches = [event allTouches];
    for (UITouch *touch in allTouches)
        for (UITouch *touch2 in allTouches)



    {
        CGPoint location = [touch locationInView:touch.view];
        CGPoint location2 = [touch2 locationInView:touch2.view];


        if ([touchArea2.layer.presentationLayer hitTest:location]) {
            touchArea2.image = [UIImage imageNamed:@"TouchAreaTouched"];

        }

        if ([touchArea.layer.presentationLayer hitTest:location]) {
           touchArea.image = [UIImage imageNamed:@"TouchAreaTouched"];
            if ([touchArea2.layer.presentationLayer hitTest:location2]) {
                touchArea2.image = [UIImage imageNamed:@"TouchAreaTouched"];
                            timerTouch = 10;
            touchTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(randomVoid) userInfo:nil repeats:YES];
            } }}
    }


-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSSet *allTouches = [event allTouches];
    for (UITouch *touch in allTouches)



          {
            CGPoint location = [touch locationInView:touch.view];
              if (![touchArea.layer.presentationLayer hitTest:location]&&![touchArea2.layer.presentationLayer hitTest:location]) {
                  touchArea.image = [UIImage imageNamed:@"TouchArea"];
                  touchArea2.image = [UIImage imageNamed:@"TouchArea"];
                  [touchTimer invalidate];
              }

                 }
}


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

    touchArea.image = [UIImage imageNamed:@"TouchArea"];
    touchArea2.image = [UIImage imageNamed:@"TouchArea"];

    [touchTimer invalidate];
}
于 2012-11-21T15:20:38.233 に答える
0
 UIView * view = [[UIView alloc] init];
    UITapGestureRecognizer * tap = nil;
    tap.numberOfTouchesRequired = 2;
    tap.delegate = self;
    [view addGestureRecognizer:tap];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{

}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

次に、2回のタッチの位置を認識し、何をするかを決定します。

于 2012-11-21T15:41:05.103 に答える
0

これを試して :

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
  UITouch *touch = [touches anyObject];
      if ([touch view] == firstimage    ) { // Do Something}
      if ([touch view] == secondimage    ) { // Do Something}
 }
于 2012-11-19T12:55:51.987 に答える