Good, I leave you the following code and a link to the project that I have done to solve your doubt, it may not be the best solution, but I hope it serves you in some way. It's basically a UIView with a UIPanGestureRecognizer
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var scrollView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
addPanGesture()
}
func addPanGesture() {
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(didScroll))
self.scrollView.addGestureRecognizer(panGesture)
}
func didScroll(sender : UIPanGestureRecognizer) {
if sender.state == .recognized {
let translation = sender.translation(in: self.scrollView).y
let y = self.scrollView.frame.origin.y
let scrollViewSize = self.scrollView.frame.size.height
let viewSize = self.view.frame.size.height
var newY = y + translation
// These conditions avoids scrollView to leave the screen
if newY > 0 {
newY = 0
} else if newY + scrollViewSize < viewSize {
newY = -scrollViewSize + viewSize
}
UIView.animate(withDuration: 0.5, animations: {
self.scrollView.frame = CGRect(x: 0,
y: newY,
width: self.scrollView.frame.width,
height: scrollViewSize)
})
}
}
}