Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func scrollViewDidScroll(_ scrollView: UIScrollView) {
- let yOffset = scrollView.contentOffset.y
- // Calculate the difference between the current and previous offset
- let deltaY = yOffset - previousScrollViewYOffset
- previousScrollViewYOffset = yOffset
- // Calculate new navigation bar height
- var newNavBarHeight = navigationBar.frame.size.height - deltaY
- // Ensure the navigation bar height doesn't go below a certain threshold
- let minNavBarHeight: CGFloat = 44 // Adjust as needed
- newNavBarHeight = max(minNavBarHeight, newNavBarHeight)
- // Ensure the navigation bar height doesn't exceed its original height
- let maxNavBarHeight = navigationController?.navigationBar.frame.size.height ?? 0
- newNavBarHeight = min(maxNavBarHeight, newNavBarHeight)
- // Update the navigation bar's frame
- navigationBar.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: newNavBarHeight)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement