|
| 1 | +// |
| 2 | +// ESRefreshFooterAnimator.swift |
| 3 | +// |
| 4 | +// Created by egg swift on 16/4/7. |
| 5 | +// Copyright (c) 2013-2015 ESPullToRefresh (https://github.com/eggswift/pull-to-refresh) |
| 6 | +// |
| 7 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +// of this software and associated documentation files (the "Software"), to deal |
| 9 | +// in the Software without restriction, including without limitation the rights |
| 10 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +// copies of the Software, and to permit persons to whom the Software is |
| 12 | +// furnished to do so, subject to the following conditions: |
| 13 | +// |
| 14 | +// The above copyright notice and this permission notice shall be included in |
| 15 | +// all copies or substantial portions of the Software. |
| 16 | +// |
| 17 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | +// THE SOFTWARE. |
| 24 | +// |
| 25 | + |
| 26 | +import UIKit |
| 27 | + |
| 28 | +public class ESRefreshFooterAnimator: UIView, ESRefreshProtocol, ESRefreshAnimatorProtocol { |
| 29 | + private let titleLabel: UILabel = UILabel.init(frame: CGRect.zero) |
| 30 | + private let indicatorView: UIActivityIndicatorView = UIActivityIndicatorView.init(activityIndicatorStyle: .Gray) |
| 31 | + |
| 32 | + public var animatorView: UIView { |
| 33 | + return self |
| 34 | + } |
| 35 | + |
| 36 | + override init(frame: CGRect) { |
| 37 | + super.init(frame: frame) |
| 38 | + addSubview(titleLabel) |
| 39 | + addSubview(indicatorView) |
| 40 | + indicatorView.hidden = true |
| 41 | + titleLabel.font = UIFont.systemFontOfSize(14.0) |
| 42 | + titleLabel.textColor = UIColor.init(white: 160.0 / 255.0, alpha: 1.0) |
| 43 | + titleLabel.textAlignment = .Center |
| 44 | + titleLabel.frame = bounds |
| 45 | + titleLabel.text = "下拉加载" |
| 46 | + } |
| 47 | + |
| 48 | + required public init(coder aDecoder: NSCoder) { |
| 49 | + fatalError("init(coder:) has not been implemented") |
| 50 | + } |
| 51 | + |
| 52 | + public func refreshAnimationDidBegin(view: ESRefreshComponent) { |
| 53 | + indicatorView.startAnimating() |
| 54 | + indicatorView.hidden = false |
| 55 | + } |
| 56 | + |
| 57 | + public func refreshAnimationDidEnd(view: ESRefreshComponent) { |
| 58 | + indicatorView.stopAnimating() |
| 59 | + indicatorView.hidden = true |
| 60 | + } |
| 61 | + |
| 62 | + public func refresh(view: ESRefreshComponent, progressDidChange progress: CGFloat) { |
| 63 | + // do nothing |
| 64 | + } |
| 65 | + |
| 66 | + public func refresh(view: ESRefreshComponent, stateDidChange state: ESRefreshViewState) { |
| 67 | + switch state { |
| 68 | + case .Loading: |
| 69 | + titleLabel.text = "加载中..." |
| 70 | + case .PullToRefresh: |
| 71 | + titleLabel.text = "下拉加载" |
| 72 | + case .ReleaseToRefresh: |
| 73 | + titleLabel.text = "下拉加载" |
| 74 | + case .NoMoreData: |
| 75 | + titleLabel.text = "暂无更多数据" |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + override public func layoutSubviews() { |
| 80 | + super.layoutSubviews() |
| 81 | + let s = self.bounds.size |
| 82 | + let w = s.width |
| 83 | + let h = s.height |
| 84 | + let s1 = titleLabel.sizeThatFits(self.bounds.size) |
| 85 | + titleLabel.frame = CGRect.init(x: (w - s1.width) / 2.0 + 8.0, y: (h - s1.height) / 2.0, width: s1.width, height: s1.height) |
| 86 | + indicatorView.center = CGPoint.init(x: titleLabel.frame.origin.x - 18.0, y: h / 2.0) |
| 87 | + } |
| 88 | +} |
0 commit comments