Audio on TouchesEnded
On TouchesEnded I want to do two things: 1) return the view to its original position - this works fine. 2) I want to play an audio sound if the touch ended on the YES vies and a different sound for the NO views.
How can I do this?
At this moment my sound for NO will play for every touch ended - and this is not good.
I am new to this so please explain the basics :) my current code below.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
yesletter1.frame = keepYesLetter1Pla开发者_如何学Pythonce;
yesletter2.frame = keepYesLetter2Place;
yesletter3.frame = keepYesLetter3Place;
yesletter4.frame = keepYesLetter4Place;
notletter1.frame = keepNoLetter1Place;
notletter2.frame = keepNoLetter2Place;
notletter3.frame = keepNoLetter3Place;
notletter4.frame = keepNoLetter4Place;
NSString *path = [[NSBundle mainBundle]
pathForResource:@"no"ofType:@"wav"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[theAudio play];
}
Solved this issue not the way i wanted but thing work now. I have 2 different sounds for some objects one sound and the other another sound. What i did is added a flag for each object and did if(flag1 == 0 || flag2 == 0 ect...) play sound 1 else play sound 2. in another method which does something else i played with the flags.
I am sure there is a better solution for this :) but things work now.
精彩评论