You might want to check Steve Hancock's answer in the similar question: UIScrollView not scrolling at all when added programmatically in Swift?
There is a lot of answers suggesting content size but this sometimes is not the solution. The problem lies in how the scroll view interacts with your views inside, and it is a good tendency to embed all your subviews inside a global UIView  which is in turn embedded in the UIScrollView. This is a rough example on how you would set it up:
let scrollView = ScrollView()
let contentView = UIView()
(initialized above for simplicity)
    scrollView.isScrollEnabled = true
    scrollView.backgroundColor = .clear
    scrollView.topAnchor.constraint(equalTo: self.view).isActive = true
    scrollView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
    scrollView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
    scrollView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true      
    scrollView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 40).isActive = true
(you always want to make your scrollview longer than your view)
    contentView.topAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true
    contentView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor).isActive = true
    contentView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor).isActive = true
    coachView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
    contentView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor, constant: -32).isActive = true
All of your subviews will go inside your contentView with their respective constraints.Technically you do not need the centerX anchors if you have a leading and a trailing but setting constraints for a scroll view can be a trial and error endeavor, especially if you have a subview with dynamic height. I have seen contentViews shift to the right for no apparent reason without the centerX anchor, and I have seen contentView lean to the left with a centerX anchor but without leading and trailing anchors
     
    
contentSizeis greater than its frame size. So you just need to setcontentSizewith height greater than scroll's frame height (in case vertical scrolling).self.view, they are the subViews ofself.view. Try the answer of @Sandeep Kumar. If it cannot fix, try to create all of subViews programmatically.