Drarok
Drarok

Reputation: 3809

Can a UIGestureRecognizer be made to work within a AVPlayerViewController?

I'm trying to allow the video player to be closed by pinching it, without any success.

func playVideo(video: MyVideoClass) {
    let playerVC = AVPlayerViewController()
    playerVC.player = AVPlayer(URL: NSURL(string: video.videourl)!)

    let pinchy = UIPinchGestureRecognizer(target: self, action: "handlePinchGesture:")
    playerVC.view.addGestureRecognizer(pinchy)

    self.presentViewController(playerVC, animated: true, completion: {
        playerVC.player!.play()
    });
}

func handlePinchGesture(sender: AnyObject) {
    print("Received gesture from \(sender)");
}

Pinching the video player UI does nothing at this point.

Upvotes: 3

Views: 1337

Answers (1)

ArtSabintsev
ArtSabintsev

Reputation: 5200

I solved this problem in the past by placing a transparent UIView on top of the Video Player. I added the pinch gesture to the transparent UIView, and when it was handled, I dismissed the video player underneath it.

Upvotes: 2

Related Questions