Skip to content

Latest commit

 

History

History
49 lines (26 loc) · 1.17 KB

File metadata and controls

49 lines (26 loc) · 1.17 KB

뷰 구현 + 도전과제

1. Top Button Action

스크롤뷰 최상단으로 스크롤해주는 함수 구현. 직접 구현해서 사용하였다.

    
    @IBAction func topButtonAction(_ sender: Any) {
        ppScrollView.setContentOffset(CGPoint(x: 0, y: -ppScrollView.contentInset.top), animated: true)
        
    }

2. Top Button이 배너가 안 보일때만 나오게 하기

이는 UIScrollViewDelegate 의 함수인 scrollViewDidScroll 함수를 이용해서 구현하였다. 이 함수는 ScrollView에서 스크롤이 일어날 때마다 불리게 되고, 이 때 지금의 위치를 고려해서 버튼을 나오게 함. 버튼을 숨기고 나타내는 데에는 isHidden 변수 사용.

extension ViewController : UIScrollViewDelegate {

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let curPos = scrollView.contentOffset
        
        if curPos.y > -scrollView.contentInset.top + 420 {
            topButton.isHidden = false
            
        }
        else{
            topButton.isHidden = true
        }
            
    }
    
    
    
}