我想播放声音上touchesEnded但我有一个问题。有迹象表明,绕开移动多个对象,因此,如果在任何物体移动时,下面的代码也是如此,它不断地播放声音。我怎么只能打一次?

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

    if(CGRectContainsRect([image1 frame], [image2 frame])){

        [self playsound];
    }
}
有帮助吗?

解决方案

如果你只希望它一定对象播放来电touchesEnded,首先需要确定目标,然后你可以做一个快速的if-then语句。

如果你只想要玩一次,那么只要给它像int playCount = 0;快变量,然后之后你将它设置为playCount = 1;大功告成演奏和做一个if-then语句上,以及(即玩,如果playCount为0时,不玩它,如果playCount为1)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top