를 만들기 위해있는 tableView를 사용하는 것은 Swift3.0스위프트 - 한 업데이트 목록 여기
private let MAX_HEIGHT: CGFloat = 100.0
override func viewDidLoad() {
super.viewDidLoad()
self.spinner = UIActivityIndicatorView(frame: CGRect(x: 0, y: -MAX_HEIGHT, width: self.view.bounds.width, height: MAX_HEIGHT))
self.spinner.activityIndicatorViewStyle = .whiteLarge
self.spinner.color = .blue
self.view.insertSubview(spinner, at: 0)
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 20
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "basicCell", for: indexPath)
cell.textLabel?.text = "The \(indexPath.row) Row"
return cell
}
과 코드 그리고 여기에 중요한 코드 : 나는 목록을 드래그 할 때,이
override func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
if -scrollView.contentOffset.y >= MAX_HEIGHT + scrollView.contentInset.top {
UIView.animate(withDuration: 0.5, animations: {
scrollView.contentInset.top += MAX_HEIGHT
})
self.update()
}
}
func update() {
self.spinner.startAnimating()
// I want to make a sleep for 2 seconds, But sleep() is not suit
UIView.animate(withDuration: 2.0, animations: {
self.view.alpha = 0.99
}, completion: { (_) -> Void in
self.view.alpha = 1.0
self.spinner.stopAnimating()
UIView.animate(withDuration: 0.5, animations: {
self.tableView.contentInset.top -= MAX_HEIGHT
})
})
}
을 할 것입니다
내가 원하는 애니메이션은 내가 드래그를 완료하면, 목록이
0123과 같은 업데이트 애니메이션을 것입니다드래그를 끝내면 scrollview.contentInset.top이 100.0으로 설정됩니다. 좀 더 길게 드래그하면 (125.0 ..) 목록에 드래그 한 위치에서 천천히 미끄러지 듯 움직이는 애니메이션이 생깁니다. 100.0
결과적으로 드래그를 끝내면 목록이 약간 슬라이드됩니다 더 길게 누른 다음 100.0으로 슬라이드하면 100.0으로 직접 이동하지 않았습니다. 리스트가 빠르게 흔들리는 것처럼 보입니다. [UIRefreshControl] 사용할 때
이 기능이 이미 처리되었는지 알고 계십니까 도움이 될 것입니다/uirefreshcontrol)? 그것을 사용하는 방법을 알고 싶다면 [이 질문] (http://stackoverflow.com/questions/24475792/how-to-use-pull-to-refresh-in-swift-2)을 확인해보십시오. –
UIRefreshControl을 사용하는 것은 유망한 솔루션으로 보이지만 일부 맞춤 애니메이션을 추가하려는 경우 UIRefreshControl은 많은 도움을 줄 수 없습니다. 그런 사용자 정의 컨트롤을 작성해야합니다. – pluto
이제 아이디어는 다음과 같습니다. 사용자 정의 UIRefreshControl (사용자 정의 애니메이션)을 만드는 방법을 찾아야합니다. –