SHARE
TWEET

Untitled

a guest Jun 19th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @IBAction func recordAudio(sender: AnyObject)
  2. {
  3.     if sender.state == UIGestureRecognizerState.Ended
  4.     {
  5.         session.setCategory(AVAudioSessionCategoryPlayback, error: nil)
  6.         recorder.stop()
  7.         recordButton.backgroundColor = UIColor.whiteColor()
  8.         save()
  9.     }
  10.     else if sender.state == UIGestureRecognizerState.Began
  11.     {
  12.         session.setCategory(AVAudioSessionCategoryRecord, error: nil)
  13.         recorder.record()
  14.         recordButton.backgroundColor = UIColor.greenColor()
  15.     }
  16.     else if sender.state == UIGestureRecognizerState.Cancelled
  17.     {
  18.         recorder.stop()
  19.         recordButton.backgroundColor = UIColor.redColor()
  20.     }
  21. }
  22.      
  23. @IBAction func recordAudio(sender: UILongPressGestureRecognizer)
  24. {
  25.     switch (sender.state)
  26.     {
  27.         case .Ended:
  28.             session.setCategory(AVAudioSessionCategoryPlayback, error: nil)
  29.             recorder.stop()
  30.             recordButton.backgroundColor = UIColor.whiteColor()
  31.             save()
  32.         case .Began:
  33.             session.setCategory(AVAudioSessionCategoryRecord, error: nil)
  34.             recorder.record()
  35.             recordButton.backgroundColor = UIColor.greenColor()
  36.         case .Cancelled, .Ended:
  37.             recorder.stop()
  38.             recordButton.backgroundColor = UIColor.redColor()
  39.         default:
  40.             break
  41.     }  
  42. }
  43.      
  44. @IBAction func recordAudio(sender: UILongPressGestureRecognizer)
  45. {
  46.     switch (sender.state)
  47.     {
  48.         case .Ended:
  49.             session.setCategory(AVAudioSessionCategoryPlayback, error: nil)
  50.             recorder.stop()
  51.             recordButton.backgroundColor = UIColor.whiteColor()
  52.             post()
  53.         case .Began:
  54.             session.setCategory(AVAudioSessionCategoryRecord, error: nil)
  55.             recorder.record()
  56.             recordButton.backgroundColor = UIColor.greenColor()
  57.         case .Cancelled:
  58.             recorder.stop()
  59.             recordButton.backgroundColor = UIColor.redColor()
  60.         case .Changed:
  61.             let touchLocation = recordGesture.locationInView(recordButton)
  62.             if (!CGRectContainsPoint(recordButton.bounds, touchLocation))
  63.             {
  64.                 // touch is outside of button
  65.                 recorder.stop()
  66.                 recordButton.backgroundColor = UIColor.whiteColor()
  67.                 break
  68.             }
  69.         default:
  70.             break
  71.     }
  72. }
  73.      
  74. @IBAction func recordAudio(sender: AnyObject)
  75. {
  76.     switch (sender.state) {
  77.         case .Ended:
  78.             session.setCategory(AVAudioSessionCategoryPlayback, error: nil)
  79.             recorder.stop()
  80.             recordButton.backgroundColor = .whiteColor()
  81.             save()
  82.         case .Began:
  83.             session.setCategory(AVAudioSessionCategoryRecord, error: nil)
  84.             recorder.record()
  85.             recordButton.backgroundColor = .greenColor()
  86.         case .Cancelled:
  87.             recorder.stop()
  88.             recordButton.backgroundColor = .redColor()
  89.         case .Changed:
  90.             // detect if the touch has gone outside of the button and stop the recording
  91.         default:
  92.             // do nothing
  93.     }
  94. }
  95.      
  96. let touchLocation = recognizer.location(in: recordButton)
  97.  
  98. if !recordButton.bounds.contains(touchLocation) {
  99. // touch is outside of button
  100. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top