To create a box that plays a sound upon tap and shows a volume slider upon long press, follow these steps:
AVFoundation
framework:main.swift35 chars3 lines
main.swift44 chars2 lines
AVAudioPlayer
object and load the sound file into it:main.swift325 chars12 lines
Gesture
modifier to handle tap and long press gestures:main.swift770 chars31 lines
main.swift44 chars2 lines
ZStack
to display the volume slider only when isChangingVolume
is true
:main.swift516 chars20 lines
The final SoundBox
struct should look something like this:
main.swift1599 chars56 lines
gistlibby LogSnag