Hiding Up The Top View When User Scrolling down and Showing it again when user scrolls up. [Like Twitter]

23 Views Asked by At

Trying to hide and show the top view based on user interaction with scroll down and up but it's happeing the way Twitter is doing.

I have tried couple of ways nothing seems to be concerete.

Link to the behviour to be acheieved https://drive.google.com/file/d/1bkGt5GESP0S3143hpEmubaaqTKpAelip/view?usp=sharing


func scrollViewDidScroll(_ scrollView: UIScrollView) {

  let offsetY = scrollView.contentOffset.y
  
  if offsetY > 100 {
    showTopView()
  } else {
    hideTopView()
  }
}

func showTopView() {
  UIView.animate(withDuration: 0.3) {
    self.topView.alpha = 1.0
  }
}

func hideTopView() {
  UIView.animate(withDuration: 0.3) {
    self.topView.alpha = 0.0
  }
}
0

There are 0 best solutions below