优惠券swift版马甲包

QQVideoRefreshHeader.swift 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // QQVideoRefreshHeader.swift
  3. // PullToRefreshKit
  4. //
  5. // Created by luoyang on 2016/12/8.
  6. // Copyright © 2016年 luoyang. All rights reserved.
  7. //
  8. import UIKit
  9. class QQVideoRefreshHeader: GTMRefreshHeader, SubGTMRefreshHeaderProtocol {
  10. let imageView = UIImageView()
  11. override init(frame: CGRect) {
  12. super.init(frame: frame)
  13. imageView.image = UIImage(named: "loading15")
  14. self.contentView.addSubview(imageView)
  15. }
  16. required init?(coder aDecoder: NSCoder) {
  17. fatalError("init(coder:) has not been implemented")
  18. }
  19. override func layoutSubviews() {
  20. super.layoutSubviews()
  21. imageView.frame = CGRect(x: 0, y: 0, width: 27, height: 10)
  22. imageView.center = CGPoint(x: self.bounds.width/2.0, y: self.bounds.height/2.0)
  23. }
  24. func toNormalState() {
  25. UIView.animate(withDuration: 0.3, animations: {
  26. self.imageView.transform = CGAffineTransform(translationX: 0, y: -50)
  27. })
  28. }
  29. func toRefreshingState() {
  30. imageView.image = nil
  31. let images = (0...29).map{return $0 < 10 ? "loading0\($0)" : "loading\($0)"}
  32. imageView.animationImages = images.map{return UIImage(named:$0)!}
  33. imageView.animationDuration = Double(images.count) * 0.04
  34. imageView.startAnimating()
  35. }
  36. func toPullingState() {
  37. UIView.animate(withDuration: 0.3, animations: {
  38. self.imageView.transform = CGAffineTransform.identity
  39. })
  40. }
  41. func toWillRefreshState() {}
  42. func changePullingPercent(percent: CGFloat) {}
  43. func willBeginEndRefershing(isSuccess: Bool) {}
  44. func willCompleteEndRefershing() {
  45. imageView.animationImages = nil
  46. imageView.stopAnimating()
  47. imageView.image = UIImage(named: "loading15")
  48. }
  49. func contentHeight() -> CGFloat {
  50. return 50
  51. }
  52. }