双击iOS时禁用AV Player中的缩放效果

时间:2018-08-22 10:54:52

标签: ios uigesturerecognizer avplayer

您好,在我的应用程序中,我正在使用AvplayerViewcontroller并在双击时要显示程序详细信息时在AvplayerViewcontroller.view上添加轻击手势。我可以显示,但视频正在缩放。我不要那种变焦效果。为了禁用此功能,我什至尝试通过禁用avplayer的userInteraction进行尝试,但是那时即使手势也没有采取用户操作(轻击)。即使我在播放器视图上添加了另一个uiview并在其上添加了手势,但仍然没有用。请指导我如何解决此问题。

2 个答案:

答案 0 :(得分:1)

更新:@NareshGadamsetty查看此内容。

如果showsPlaybackControls=false,则只需将UITapGestureRecognizer添加到contentOverlayView

class MyPlayerViewController: AVPlayerViewController, UIGestureRecognizerDelegate {

    func addPlayer()
        ...
        ...

        showsPlaybackControls=false

        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(showDetail))
        tapGesture.numberOfTapsRequired = 2
        contentOverlayView?.addGestureRecognizer(tapGesture)
    }

    func showDetail() {
        // Do whatever you want to do in this method
    }
}

否则实施UIGestureRecognizerDelegate

class MyPlayerViewController: AVPlayerViewController, UIGestureRecognizerDelegate {

    func addPlayer()
        ...
        ...
    }

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        if touch.tapCount == 2 {
            showDetail()
            return false
        }

        return true
    }

    private func showDetail() {
        // Do whatever you want to do in this method
    }

}

答案 1 :(得分:0)

只需将UIView作为具有清晰backgroundColor的子视图添加到玩家的视图,然后在该视图上添加所需的手势即可。喜欢:

[playerViewController.view addSubview:YourView];