gpt4 book ai didi

ios - 当我触摸播放器(MPMovieplayerController)时,点击手势不起作用

转载 作者:行者123 更新时间:2023-11-30 13:54:18 25 4
gpt4 key购买 nike

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

编辑:

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()

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

最佳答案

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

}

关于ios - 当我触摸播放器(MPMovieplayerController)时,点击手势不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33839930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com