Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let photoButton:UIButton = {
- let but = UIButton(type: .custom)
- but.layer.cornerRadius = 40
- but.layer.borderColor = UIColor.white.cgColor
- but.layer.borderWidth = 4
- but.clipsToBounds = true
- but.addTarget(self, action: #selector(takeVideo), for: .touchDown)
- but.addTarget(self, action: #selector(stopVideo), for: [.touchUpInside, .touchUpOutside])
- but.translatesAutoresizingMaskIntoConstraints = false
- return but
- }()
- @objc func takeVideo() {
- progressBar.isHidden = false
- timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(updateProgressbar), userInfo: nil, repeats: true)
- timer?.fire()
- }
- @objc func stopVideo() {
- timer?.invalidate()
- // stop video
- }
- @objc private func updateProgressbar() {
- let maxLength = 7.0
- let difference = Date().timeIntervalSince1970 - (timer?.fireDate.timeIntervalSince1970)!
- progressBar.progress = Float(difference / maxLength)
- if difference >= maxLength {
- stopVideo() // Invalidates the timer and will stop video.
- }
- }
- let recorder = RecorderViewController()
- recorder.db = db
- DispatchQueue.main.async(execute: {
- self.present(recorder, animated: true, completion: nil)
- })
Add Comment
Please, Sign In to add comment