Guest User

Untitled

a guest
May 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. let photoButton:UIButton = {
  2. let but = UIButton(type: .custom)
  3. but.layer.cornerRadius = 40
  4. but.layer.borderColor = UIColor.white.cgColor
  5. but.layer.borderWidth = 4
  6. but.clipsToBounds = true
  7. but.addTarget(self, action: #selector(takeVideo), for: .touchDown)
  8. but.addTarget(self, action: #selector(stopVideo), for: [.touchUpInside, .touchUpOutside])
  9. but.translatesAutoresizingMaskIntoConstraints = false
  10. return but
  11. }()
  12.  
  13. @objc func takeVideo() {
  14. progressBar.isHidden = false
  15.  
  16. timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(updateProgressbar), userInfo: nil, repeats: true)
  17. timer?.fire()
  18. }
  19.  
  20. @objc func stopVideo() {
  21. timer?.invalidate()
  22. // stop video
  23. }
  24.  
  25. @objc private func updateProgressbar() {
  26. let maxLength = 7.0
  27. let difference = Date().timeIntervalSince1970 - (timer?.fireDate.timeIntervalSince1970)!
  28.  
  29. progressBar.progress = Float(difference / maxLength)
  30. if difference >= maxLength {
  31. stopVideo() // Invalidates the timer and will stop video.
  32. }
  33. }
  34.  
  35. let recorder = RecorderViewController()
  36. recorder.db = db
  37. DispatchQueue.main.async(execute: {
  38. self.present(recorder, animated: true, completion: nil)
  39. })
Add Comment
Please, Sign In to add comment