99import Foundation
1010import UIKit
1111
12+
1213class TaoBaoRefreshHeader : UIView , RefreshableHeader {
1314 private let circleLayer = CAShapeLayer ( )
1415 private let arrowLayer = CAShapeLayer ( )
@@ -18,12 +19,20 @@ class TaoBaoRefreshHeader:UIView,RefreshableHeader{
1819 super. init ( frame: frame)
1920 setUpCircleLayer ( )
2021 setUpArrowLayer ( )
21- textLabel. frame = CGRectMake ( CGRectGetWidth ( self . bounds ) / 2 - 30 , CGRectGetHeight ( self . bounds ) / 2 - 20 , 120 , 40 )
22+ textLabel. frame = CGRectMake ( 0 , 0 , 120 , 40 )
2223 textLabel. textAlignment = . Center
2324 textLabel. textColor = UIColor . lightGrayColor ( )
2425 textLabel. font = UIFont . systemFontOfSize ( 14 )
2526 textLabel. text = " 下拉即可刷新... "
27+ let imageView = UIImageView ( frame: CGRectMake ( 0 , 0 , 230 , 35 ) )
28+ imageView. image = UIImage ( named: " taobaoLogo " )
29+ self . addSubview ( imageView)
2630 self . addSubview ( textLabel)
31+ //放置Views和Layer
32+ imageView. center = CGPointMake ( CGRectGetWidth ( frame) / 2 , CGRectGetHeight ( frame) - 60 - 18 )
33+ textLabel. center = CGPointMake ( CGRectGetWidth ( frame) / 2 + 20 , CGRectGetHeight ( frame) - 30 )
34+ self . arrowLayer. position = CGPointMake ( CGRectGetWidth ( frame) / 2 - 60 , CGRectGetHeight ( frame) - 30 )
35+ self . circleLayer. position = CGPointMake ( CGRectGetWidth ( frame) / 2 - 60 , CGRectGetHeight ( frame) - 30 )
2736 }
2837 func setUpArrowLayer( ) {
2938 let bezierPath = UIBezierPath ( )
@@ -38,7 +47,6 @@ class TaoBaoRefreshHeader:UIView,RefreshableHeader{
3847 self . arrowLayer. lineWidth = 1.0
3948 self . arrowLayer. lineCap = kCALineCapRound
4049 self . arrowLayer. bounds = CGRectMake ( 0 , 0 , 40 , 40 )
41- self . arrowLayer. position = CGPointMake ( CGRectGetWidth ( self . bounds) / 2.0 - 60 , CGRectGetHeight ( self . bounds) / 2.0 )
4250 self . arrowLayer. anchorPoint = CGPointMake ( 0.5 , 0.5 )
4351 self . layer. addSublayer ( self . arrowLayer)
4452 }
@@ -56,7 +64,6 @@ class TaoBaoRefreshHeader:UIView,RefreshableHeader{
5664 self . circleLayer. lineWidth = 1.0
5765 self . circleLayer. lineCap = kCALineCapRound
5866 self . circleLayer. bounds = CGRectMake ( 0 , 0 , 40 , 40 )
59- self . circleLayer. position = CGPointMake ( CGRectGetWidth ( self . bounds) / 2.0 - 60 , CGRectGetHeight ( self . bounds) / 2.0 )
6067 self . circleLayer. anchorPoint = CGPointMake ( 0.5 , 0.5 )
6168 self . layer. addSublayer ( self . circleLayer)
6269 }
@@ -70,7 +77,9 @@ class TaoBaoRefreshHeader:UIView,RefreshableHeader{
7077 }
7178 func percentUpdateWhenNotRefreshing( percent: CGFloat ) {
7279 let adjustPercent = max ( min ( 1.0 , percent) , 0.0 )
73- self . circleLayer. strokeEnd = 0.05 + ( 0.95 - 0.05 ) * adjustPercent
80+ transitionWithOutAnimation {
81+ self . circleLayer. strokeEnd = 0.05 + ( 0.95 - 0.05 ) * adjustPercent
82+ } ;
7483 if adjustPercent == 1.0 {
7584 textLabel. text = " 释放即可刷新... "
7685 } else {
@@ -89,12 +98,22 @@ class TaoBaoRefreshHeader:UIView,RefreshableHeader{
8998 textLabel. text = " 刷新中... "
9099 }
91100 func didBeginEndRefershingAnimation( result: RefreshResult ) {
92- self . circleLayer. strokeEnd = 0.05
101+ transitionWithOutAnimation {
102+ self . circleLayer. strokeEnd = 0.05
103+ } ;
93104 self . circleLayer. removeAllAnimations ( )
94105 }
95106 func didCompleteEndRefershingAnimation( result: RefreshResult ) {
96- self . circleLayer. strokeEnd = 0.05
107+ transitionWithOutAnimation {
108+ self . circleLayer. strokeEnd = 0.05
109+ } ;
97110 self . arrowLayer. hidden = false
98111 textLabel. text = " 下拉即可刷新 "
99112 }
113+ func transitionWithOutAnimation( clousre: ( ) -> ( ) ) {
114+ CATransaction . begin ( )
115+ CATransaction . setDisableActions ( true )
116+ clousre ( )
117+ CATransaction . commit ( )
118+ }
100119}
0 commit comments