@@ -47,8 +47,6 @@ extension ThirdViewController
47
47
override func viewDidAppear( _ animated: Bool )
48
48
{
49
49
super. viewDidAppear ( animated)
50
- // 必须在view完全加载好再调用这个方法,否则就会出现白块的状况
51
- scrollViewDidScroll ( self . tableView)
52
50
tableView. delegate = self ;
53
51
}
54
52
@@ -59,6 +57,41 @@ extension ThirdViewController
59
57
navigationController? . navigationBar. wr_setTranslationY ( translationY: 0 )
60
58
}
61
59
60
+ func scrollViewDidEndDecelerating( _ scrollView: UIScrollView )
61
+ {
62
+ stopScroll ( scrollView)
63
+ }
64
+
65
+ func scrollViewDidEndDragging( _ scrollView: UIScrollView , willDecelerate decelerate: Bool )
66
+ {
67
+ if decelerate == false {
68
+ stopScroll ( scrollView)
69
+ }
70
+ }
71
+
72
+ func stopScroll( _ scrollView: UIScrollView )
73
+ {
74
+ let offsetY = scrollView. contentOffset. y
75
+ // 向上滑动的距离
76
+ let scrollUpHeight = offsetY - NAVBAR_TRANSLATION_POINT
77
+ if ( scrollUpHeight >= 22 )
78
+ { // 超过导航栏高度的一半,只显示状态栏
79
+ UIView . animate ( withDuration: 0.3 , animations: { [ weak self] in
80
+ if let weakSelf = self {
81
+ weakSelf. setNavigationBarTransformProgress ( progress: 1 )
82
+ }
83
+ } )
84
+ }
85
+ else
86
+ { // 没有超过导航栏高度的一半,导航栏全部显示
87
+ UIView . animate ( withDuration: 0.3 , animations: { [ weak self] in
88
+ if let weakSelf = self {
89
+ weakSelf. setNavigationBarTransformProgress ( progress: 0 )
90
+ }
91
+ } )
92
+ }
93
+ }
94
+
62
95
func scrollViewDidScroll( _ scrollView: UIScrollView )
63
96
{
64
97
let offsetY = scrollView. contentOffset. y
0 commit comments