Tag: 正常化

与AVPlayer的平移手势

这个function对我的应用程序非常重要,并且真的很想帮助一下。 基本上,我想添加一个UIPanGestureRecognizer到video播放器,以便用户可以用手势快进/倒带video。 苹果有一些使用Swift 3的示例代码,并且已经创build了整个video播放器。 唯一缺less的是UIPanGestureRecognizer 。 这是链接: https : //developer.apple.com/library/content/samplecode/AVFoundationSimplePlayer-iOS/Introduction/Intro.html#//apple_ref/doc/uid/TP40016103 在viewWillAppear我添加了这样的手势: let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture)) view.addGestureRecognizer(panGesture) 这是有点工作的代码。 目前正在擦洗。 问题是,每次我开始平移手势,video跳到中间,我从那里开始。 而不是从当前video的快进/快退,平移手势将video跳到中间,然后允许我快进/快退,这是不好的。 func handlePanGesture(sender: UIPanGestureRecognizer) { switch sender.state { case .began, .changed: let translation = sender.translation(in: self.view) var horizontalTranslation = Float(translation.x) let durationInSeconds = Float(CMTimeGetSeconds(player.currentItem!.asset.duration)) // Using 275 as the limit for delta along […]