当我触摸我的播放器时,轻触手势无效(MPMovieplayerController)

时间:2015-11-21 05:10:10

标签: ios swift mpmovieplayercontroller uitapgesturerecognizer

这里我尝试合并所有视频并在屏幕上显示该视频。但我需要添加轻击手势,当我按下播放器屏幕时,它应该处理一些动作。但如果我查看它的工作,但如果我点击播放器它不工作。任何解决方案

编辑:

class ViewController: UIViewController,UIGestureRecognizerDelegate {




 var location: CGPoint!



    var gestureRecognizer: UITapGestureRecognizer!

    var videoPlayer = MPMoviePlayerController()





    override func viewDidLoad() {
        super.viewDidLoad()
        musicImg.hidden = true
        let gestureRecognizer: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "handleTapGesture")

        gestureRecognizer.delegate = self;
        videoPlayer.view.addGestureRecognizer(gestureRecognizer)


    }


    func handleTap(gestureRecognizer: UIGestureRecognizer) {
        //location = gestureRecognizer .locationInView(videoPlayer.view)
        print("tapped")
    }

    //#pragma mark - gesture delegate
    // this allows you to dispatch touches

    func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {

        return true

    }

   func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,
        shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
            return true


    }

在屏幕上显示我选择的视频:

self.mediaUI.dismissViewControllerAnimated(true, completion: nil)
                        self.videoPlayer = MPMoviePlayerController()
                        self.videoPlayer.contentURL = self.videoURL


                        self.videoPlayer.controlStyle = .Embedded

                        self.videoPlayer.scalingMode = .AspectFill

                        self.videoPlayer.shouldAutoplay = true

                        self.videoPlayer.backgroundView.backgroundColor = UIColor.clearColor()
                        self.videoPlayer.fullscreen = true
                        self.videoPlayer.view.frame = CGRectMake(38, 442, 220, 106)

                        self.view.addSubview(self.videoPlayer.view)

                        self.videoPlayer.play()
                        self.videoPlayer.prepareToPlay()

我的屏幕显示全白,没有按钮,标签显示

1 个答案:

答案 0 :(得分:0)

Try with this...

  let gestureRecognizer: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "handleTapGesture")

  gestureRecognizer.delegate = self;



If you want to add gesture in movie player controller


   videoPlayer.view.addGestureRecognizer(gestureRecognizer)


and if you want for main screen...


  self.view.addGestureRecognizer(gestureRecognizer)



And implement delegate methods


 #pragma mark - gesture delegate
 // this allows you to dispatch touches

  func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {

    return true

  }
// this enables you to handle multiple recognizers on single view
 func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer touch: UITouch) -> Bool {

    return true

}