Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4d355d3

Browse files
解决移动导航栏后右滑返回中途取消的bug
1 parent 2c0eaac commit 4d355d3

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

‎WRNavigationBar_swift/WRNavigationBar_swift/Demos/SixthViewController.swift‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ extension SixthViewController
5252
override func viewDidAppear(_ animated: Bool)
5353
{
5454
super.viewDidAppear(animated)
55-
// 必须在view完全加载好再调用这个方法,否则就会出现白块的状况
56-
scrollViewDidScroll(self.tableView)
5755
tableView.delegate = self;
5856
}
5957

‎WRNavigationBar_swift/WRNavigationBar_swift/Demos/ThirdViewController.swift‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ extension ThirdViewController
4747
override func viewDidAppear(_ animated: Bool)
4848
{
4949
super.viewDidAppear(animated)
50-
// 必须在view完全加载好再调用这个方法,否则就会出现白块的状况
51-
scrollViewDidScroll(self.tableView)
5250
tableView.delegate = self;
5351
}
5452

@@ -59,6 +57,41 @@ extension ThirdViewController
5957
navigationController?.navigationBar.wr_setTranslationY(translationY: 0)
6058
}
6159

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+
6295
func scrollViewDidScroll(_ scrollView: UIScrollView)
6396
{
6497
let offsetY = scrollView.contentOffset.y

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /