extension HomeViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
//스크롤뷰의 현재 위치
let offset = scrollView.contentOffset.y
//MARK: 이미지 stick to top 애니메이션
if offset < 0 {
slideShow.heightConstraint?.constant = 240 - offset
headerTopConstraint.constant = offset
} else {
slideShow.heightConstraint?.constant = 240
}
//MARK: 네비게이션 바 fade animation
var proportionalOffset = offset / 60
if proportionalOffset > 1 {
proportionalOffset = 1
let color = UIColor(red: 1, green: 1, blue: 1, alpha: proportionalOffset)
self.navigationController?.navigationBar.tintColor = UIColor(hue: 1, saturation: 0, brightness: 1 - proportionalOffset, alpha: 1)
self.navigationController?.navigationBar.backgroundColor = color
UIApplication.statusBarBackgroundColor = color
} else {
let color = UIColor(red: 1, green: 1, blue: 1, alpha: proportionalOffset)
self.navigationController?.navigationBar.tintColor = UIColor(hue: 1, saturation: 0, brightness: 1 - proportionalOffset, alpha: 1)
self.navigationController?.navigationBar.backgroundColor = color
UIApplication.statusBarBackgroundColor = color
}
}
}
Swift
복사