I created a stack view with 2 buttons called
Services and Customize
My goal is to make this stack view disappear when I scroll down and make it appear again when I scroll up. Everything works as it should be when I scroll down but when I scroll up, the stack view, I named it
menuStack
it overlaps with the tableview. The tableView is the one that contains images of a shoe as you can see in the screenshot.
I tried this delegate for scrollview but I think something is missing in my anchors. Here are 3 screenshots of each events.
When I scroll up the menuStack does not reappear
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
self.menuStack.translatesAutoresizingMaskIntoConstraints = false
if targetContentOffset.pointee.y < scrollView.contentOffset.y {
//scroll up
self.menuStack.isHidden = true
if #available(iOS 11.0, *) {
let safeGuide = self.view.safeAreaLayoutGuide
self.menuStack.topAnchor.constraint(equalTo: safeGuide.topAnchor).isActive = true
self.menuStack.bottomAnchor.constraint(equalTo: self.tableView.topAnchor, constant: 50).isActive = true
self.tableView.topAnchor.constraint(equalTo: safeGuide.topAnchor, constant: 100).isActive = true
} else {
// Fallback on earlier versions
}
self.menuStack.isHidden = false
} else {
//scroll down
self.menuStack.isHidden = true
if #available(iOS 11.0, *) {
let safeGuide = self.view.safeAreaLayoutGuide
self.tableView.topAnchor.constraint(equalTo: safeGuide.topAnchor).isActive = true
} else {
// Fallback on earlier versions
}
}
}