How can I add Swipe Gesture to AVPlayer in swift 3

前端 未结 4 809
天命终不由人
天命终不由人 2021-01-01 04:51

I am using Swift 3 and I want to add swipe gesture to AVPlayer. Somebody told me that in order to do this I have to use another view and bring that view to the

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-01 05:44

    Swift 4

    You can do it without sView, just add a gesture recognizer to AVPlayerViewController's view:

    func playVideo() {
        let playerController = AVPlayerViewController()
        playerController.player = AVPlayer(url: URL(fileURLWithPath: videoPath))
        playerController.showsPlaybackControls = false
        playerController.view.isUserInteractionEnabled = true
    
        let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
        swipeUp.direction = UISwipeGestureRecognizerDirection.up
        playerController.view.addGestureRecognizer(swipeUp)
    
        present(playerController, animated: false) {
            playerController.player?.play()
        }
    }
    
    @objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
        print("swipe up")
    }
    

提交回复
热议问题