我试图在 TouchsEnded 上播放声音,但遇到问题。有多个对象会四处移动,因此如果以下代码在任何对象移动时成立,则它会不断播放声音。我怎样才能只玩一次?
-(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,则不播放)。
关于ios - 触摸结束声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2516300/