I'm wondering what is the best way for me to record sound while the user is holding down a UIButton. (ie start when the user is holding down and stop when he releases the button). Will something like this work?
Function call
button.addTarget(self, action: "holding:", forControlEvents: .TouchDown)
Function:
func holding (sender:UIButton!) {
// Sound recording code here
}
Also I'm trying to update a UIProgressView as the sound is recorded. Is there a way I can access the amount of time (in seconds / milliseconds) that has elapsed since the recording has started? Can I just use my own timer or will there be some dependency?
I had a similar requirement recently, and instead of using a UIButton
I used a regular view ( UILabel
, UIImageView
or whatever you want the 'button' to look like) with a UILongPressGestureRecognizer
added. The gesture recognizer's target function can then stop/start recording as needed:
func holding (sender:UILongPressGestureRecognizer!) {
// If the gesture state is UIGestureRecognizerStateBegan start recording
// If it is UIGestureRecognizerStateEnded stop recording
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.