I have a UIScrollView in which I have taken a view that will scroll with other views when it comes to the top it will stick to the top of the screen but I have another pagination on the same page for that I changed UIScrollView height for each page and because of that sticky view goes to its original position I have printed frame and content offset of scrollview and sticky view but when new height is set no change is shown in observers but if scroll a bit after it again reappears to top of the screen.
I have used parchment for paging and each page has the dynamic size that I have changed by setting the container view height constraint. the container view has parchment paging view.
func pagingViewController(_ pagingViewController: PagingViewController, didScrollToItem pagingItem: PagingItem, startingViewController: UIViewController?, destinationViewController: UIViewController, transitionSuccessful: Bool) {
if transitionSuccessful {
let index = viewcontrollers?.firstIndex(of: destinationViewController)
self.detailsTabPageControl.currentPage = index ?? 0
if let vc = destinationViewController as? MarketsViewController
{
self.view.isUserInteractionEnabled = false
vc.reloadMatchData()
} else if let vc = destinationViewController as? CommentaryViewController {
let tableheight = ((8 * 41) * 6) + (6 * 75)
self.pagingViewHeightConstraint.constant = pagingViewBaseHeight > CGFloat(tableheight) ? pagingViewBaseHeight : CGFloat(tableheight + 10)
self.heightConstraint = self.pagingViewHeightConstraint.constant
} else if let vc = destinationViewController as? ScoreChartViewController {
self.pagingViewHeightConstraint.constant = pagingViewBaseHeight > vc.scrollContentView.frame.height ? pagingViewBaseHeight : (vc.scrollContentView.frame.height + 20)
}
}
}
If I comment above line then this issue doesn't come.
observer I have added to check the change in UIScrollview and sticky view
self.mainScrollView.addObserver(self, forKeyPath: #keyPath(UIScrollView.contentOffset), options: [.old, .new], context: nil)
self.shadowView.addObserver(self, forKeyPath: #keyPath(UIView.frame), options: [.old, .new], context: nil)
self.mainScrollView.addObserver(self, forKeyPath: "contentSize", options: [.new, .old, .prior], context: nil)