scrollViewDidScroll delegate metodunu kullanarak basitçe şöyle birşey yapılabilir mesela;
class ViewController: UIViewController, UIScrollViewDelegate {
var myScroll:UIScrollView! = nil
var refreshIndıcatorHolder:UIView! = nil
var refreshIndıcatorHolderHeight:CGFloat = 50
var refreshIndicator:UIView! = nil
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.myScroll = UIScrollView(frame: self.view.frame)
self.myScroll.delegate = self
self.myScroll.backgroundColor = UIColor.grayColor()
self.view.addSubview(self.myScroll)
var scrollViewDummyContent:UIView = UIView(frame: CGRectMake(10.0, 10.0, self.view.frame.size.width - 20, self.view.frame.size.height * 2))
scrollViewDummyContent.backgroundColor = UIColor.redColor()
self.myScroll.addSubview(scrollViewDummyContent)
self.myScroll.contentSize = CGSizeMake(scrollViewDummyContent.frame.size.width, scrollViewDummyContent.frame.size.height + 10)
self.refreshIndıcatorHolder = UIView(frame: CGRectMake(0.0, -self.refreshIndıcatorHolderHeight, self.view.frame.size.width, self.refreshIndıcatorHolderHeight))
self.refreshIndıcatorHolder.backgroundColor = UIColor.blueColor()
self.view.addSubview(self.refreshIndıcatorHolder)
self.refreshIndicator = UIView(frame: CGRectMake((self.refreshIndıcatorHolder.frame.size.width - (self.refreshIndıcatorHolder.frame.size.width * 0.6)) / 2, (self.refreshIndıcatorHolder.frame.size.height - (self.refreshIndıcatorHolder.frame.size.height * 0.8)) / 2, self.refreshIndıcatorHolder.frame.size.width * 0.6, self.refreshIndıcatorHolder.frame.size.height * 0.8))
self.refreshIndicator.backgroundColor = UIColor.yellowColor()
self.refreshIndıcatorHolder.addSubview(self.refreshIndicator)
self.refreshIndicator.transform = CGAffineTransformMakeScale(0.0, 0.0)
}
func scrollViewDidScroll(scrollView: UIScrollView) {
if self.myScroll.contentOffset.y < 0 {
animateRefreshIndicatorWhilePullDown(self.myScroll.contentOffset.y)
}
}
func animateRefreshIndicatorWhilePullDown(yScrollValue:CGFloat) {
var absYScrollValue:CGFloat = fabs(yScrollValue)
if absYScrollValue > 0 {
var refreshIndıcatorHolderFrame:CGRect = self.refreshIndıcatorHolder.frame
refreshIndıcatorHolderFrame.origin.y = absYScrollValue - self.refreshIndıcatorHolderHeight
if refreshIndıcatorHolderFrame.origin.y < 0 {
self.refreshIndıcatorHolder.frame = refreshIndıcatorHolderFrame
} else {
refreshIndıcatorHolderFrame.origin.y = 0
self.refreshIndıcatorHolder.frame = refreshIndıcatorHolderFrame
}
var scaleRatio:CGFloat = (self.refreshIndıcatorHolderHeight + refreshIndıcatorHolderFrame.origin.y) / self.refreshIndıcatorHolderHeight
self.refreshIndicator.transform = CGAffineTransformMakeScale(scaleRatio, scaleRatio)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}