Advertisement
astrou123

Untitled

Apr 1st, 2024
2,158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.04 KB | None | 0 0
  1.     func scrollViewDidScroll(_ scrollView: UIScrollView) {
  2.         let yOffset = scrollView.contentOffset.y
  3.        
  4.         // Calculate the difference between the current and previous offset
  5.         let deltaY = yOffset - previousScrollViewYOffset
  6.         previousScrollViewYOffset = yOffset
  7.        
  8.         // Calculate new navigation bar height
  9.         var newNavBarHeight = navigationBar.frame.size.height - deltaY
  10.        
  11.         // Ensure the navigation bar height doesn't go below a certain threshold
  12.         let minNavBarHeight: CGFloat = 44 // Adjust as needed
  13.         newNavBarHeight = max(minNavBarHeight, newNavBarHeight)
  14.        
  15.         // Ensure the navigation bar height doesn't exceed its original height
  16.         let maxNavBarHeight = navigationController?.navigationBar.frame.size.height ?? 0
  17.         newNavBarHeight = min(maxNavBarHeight, newNavBarHeight)
  18.        
  19.         // Update the navigation bar's frame
  20.         navigationBar.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: newNavBarHeight)
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement