我目前正在尝试复制iOS控制面板的解散交互。到目前为止,我只能通过向下滑动来解散视图。我向上滑动时无法复制相同的弹性,向上滑动后向下滑动或通常只是在播放视图时无法复制平滑过渡。
这是我在视图中的handlePan处理程序,我试图解雇:
func handlePan(recognizer: UIPanGestureRecognizer) {
let translation = recognizer.translation(in: self)
switch recognizer.state {
case .began:
self._displayPosition = self.frame
self._dismissAnimator = UIViewPropertyAnimator(duration: 0.75, curve: .easeOut)
self._dismissAnimator.pauseAnimation()
case .changed:
if translation.y < 0 {
self._dismissAnimator.addAnimations {
self.frame = self._displayPosition.offsetBy(dx: 0, dy: -20)
}
self._dismissAnimator.fractionComplete = -translation.y*0.10/20
} else {
self._dismissAnimator.addAnimations {
self.frame = self._displayPosition.offsetBy(dx: 0, dy: self._offsetFromScreenBottom)
}
self._dismissAnimator.fractionComplete = translation.y / self._offsetFromScreenBottom
}
case .ended:
if self.frame.origin.y < self._displayPosition.origin.y {
self._dismissAnimator.stopAnimation(true)
self._dismissAnimator.addAnimations {
self.frame = self._displayPosition
}
self._dismissAnimator.startAnimation()
} else {
self._dismissAnimator.continueAnimation(withTimingParameters: nil, durationFactor: 0)
}
default:
self._dismissAnimator.finishAnimation(at: .start)
}
}
提前致谢!