Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @IBAction func recordAudio(sender: AnyObject)
- {
- if sender.state == UIGestureRecognizerState.Ended
- {
- session.setCategory(AVAudioSessionCategoryPlayback, error: nil)
- recorder.stop()
- recordButton.backgroundColor = UIColor.whiteColor()
- save()
- }
- else if sender.state == UIGestureRecognizerState.Began
- {
- session.setCategory(AVAudioSessionCategoryRecord, error: nil)
- recorder.record()
- recordButton.backgroundColor = UIColor.greenColor()
- }
- else if sender.state == UIGestureRecognizerState.Cancelled
- {
- recorder.stop()
- recordButton.backgroundColor = UIColor.redColor()
- }
- }
- @IBAction func recordAudio(sender: UILongPressGestureRecognizer)
- {
- switch (sender.state)
- {
- case .Ended:
- session.setCategory(AVAudioSessionCategoryPlayback, error: nil)
- recorder.stop()
- recordButton.backgroundColor = UIColor.whiteColor()
- save()
- case .Began:
- session.setCategory(AVAudioSessionCategoryRecord, error: nil)
- recorder.record()
- recordButton.backgroundColor = UIColor.greenColor()
- case .Cancelled, .Ended:
- recorder.stop()
- recordButton.backgroundColor = UIColor.redColor()
- default:
- break
- }
- }
- @IBAction func recordAudio(sender: UILongPressGestureRecognizer)
- {
- switch (sender.state)
- {
- case .Ended:
- session.setCategory(AVAudioSessionCategoryPlayback, error: nil)
- recorder.stop()
- recordButton.backgroundColor = UIColor.whiteColor()
- post()
- case .Began:
- session.setCategory(AVAudioSessionCategoryRecord, error: nil)
- recorder.record()
- recordButton.backgroundColor = UIColor.greenColor()
- case .Cancelled:
- recorder.stop()
- recordButton.backgroundColor = UIColor.redColor()
- case .Changed:
- let touchLocation = recordGesture.locationInView(recordButton)
- if (!CGRectContainsPoint(recordButton.bounds, touchLocation))
- {
- // touch is outside of button
- recorder.stop()
- recordButton.backgroundColor = UIColor.whiteColor()
- break
- }
- default:
- break
- }
- }
- @IBAction func recordAudio(sender: AnyObject)
- {
- switch (sender.state) {
- case .Ended:
- session.setCategory(AVAudioSessionCategoryPlayback, error: nil)
- recorder.stop()
- recordButton.backgroundColor = .whiteColor()
- save()
- case .Began:
- session.setCategory(AVAudioSessionCategoryRecord, error: nil)
- recorder.record()
- recordButton.backgroundColor = .greenColor()
- case .Cancelled:
- recorder.stop()
- recordButton.backgroundColor = .redColor()
- case .Changed:
- // detect if the touch has gone outside of the button and stop the recording
- default:
- // do nothing
- }
- }
- let touchLocation = recognizer.location(in: recordButton)
- if !recordButton.bounds.contains(touchLocation) {
- // touch is outside of button
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement