Button 触摸开始,触摸移动

Button 触摸开始,触摸移动,button,detect,touchesbegan,touchesmoved,Button,Detect,Touchesbegan,Touchesmoved,我的问题是,当我按下一个按钮时,它会发出声音,此时我触摸另一个手指的同一个按钮,它也会发出声音。那么,当我已经按住同一按钮上的一个手指时,我可以禁用另一个触摸吗?同样的问题也一样 int触摸计数 -(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件{ } (无效)触控取消:(NSSet*)触控事件:(UIEvent*)事件{ [self-touchesedend:toucheevent:event]; } 由于您使用点击点坐标检测“按钮”的触摸,您只需在触摸中添加逻辑即可开始

我的问题是,当我按下一个按钮时,它会发出声音,此时我触摸另一个手指的同一个按钮,它也会发出声音。那么,当我已经按住同一按钮上的一个手指时,我可以禁用另一个触摸吗?同样的问题也一样

int触摸计数

-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件{

}

  • (无效)触控取消:(NSSet*)触控事件:(UIEvent*)事件{ [self-touchesedend:toucheevent:event]; }

由于您使用点击点坐标检测“按钮”的触摸,您只需在触摸中添加逻辑即可开始检查按钮是否已点击。例如,在类中添加一个“BOOL button1Tapped”变量

UITouch *touch = [touches anyObject];

CGPoint touchLocation = [touch locationInView:self.view];

if(CGRectContainsPoint(img1.frame,touchLocation)){

    if (!img1.isHighlighted && touchesCount < 1){

        [img1 setHighlighted:YES];
        [img2 setHighlighted:NO];


        NSLog(@" Image 1");

        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"c", CFSTR ("mp3"), NULL);

        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID);
    }
}else {
    [img1 setHighlighted:NO];

}if (CGRectContainsPoint(img2.frame,touchLocation)){

    if (!img2.isHighlighted && touchesCount < 1){

        [img2 setHighlighted:YES];
        [img1 setHighlighted:NO];

        NSLog(@" Image 2");

        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"d", CFSTR ("mp3"), NULL);

        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID);
    }
}else {
    [img2 setHighlighted:NO];
}
UITouch *touch = [touches anyObject];

CGPoint touchLocation = [touch locationInView:self.view];

if(CGRectContainsPoint(img1.frame,touchLocation)){

    if (!img1.isHighlighted && touchesCount < 1){

        [img1 setHighlighted:YES];
        [img2 setHighlighted:NO];

        NSLog(@" Image 1");

    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"c", CFSTR ("mp3"), NULL);

    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);
    }
}else {
    [img1 setHighlighted:NO];

}if (CGRectContainsPoint(img2.frame,touchLocation)){

     if (!img2.isHighlighted && touchesCount < 1){

         [img2 setHighlighted:YES];
         [img1 setHighlighted:NO];

    NSLog(@" Image 2");

    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"d", CFSTR ("mp3"), NULL);

    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);
     }
}else {
    [img2 setHighlighted:NO];
}
[img1 setHighlighted:NO];
[img2 setHighlighted:NO];