I have a scroll view that can be scrolled to the sides (only left and right, not up and down).
I want to play a short sound (less than a second) whenever the scroll view is moved X pixels to either side.
How can this be done? Code samples will be greatly appreciated…
Thanks,
Here is the code I used:
I added the SoundEffect.h and SoundEffect.m files to my project (you can find them online).
Then, I created a sound effect instance:
Then, I setup my UIViewController as the delegate of my UIScrollView by adding
<UIScrollViewDelegate>to the .h file of the view controller and setting the relevant outlet of the UIScrollView.In the
-(void)viewDidLoadmethod, I initialized my sound effect:And then, I implemented these two methods:
I needed the sound effect to fire every 55 pixels to either direction, but you can change this to a constant value that fits your needs.
It works great for me, and hopefully, it will help others as well…