Skip to content

Commit d2d34df

Browse files
committed
完成蚂蚁森林demo实现
1 parent 9476a57 commit d2d34df

File tree

5 files changed

+153
-0
lines changed

5 files changed

+153
-0
lines changed

WRNavigationBar_swift/WRNavigationBar_swift.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
1A869EDF1ECAA36B006D96F8 /* CustomNavBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A869EDE1ECAA36B006D96F8 /* CustomNavBarController.swift */; };
2222
1A96559C1ED6B64F00A89E30 /* CustomListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A96559B1ED6B64F00A89E30 /* CustomListController.swift */; };
2323
1A96559E1ED6B8C600A89E30 /* MoveListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A96559D1ED6B8C600A89E30 /* MoveListController.swift */; };
24+
1A966E8D1EE048F60045FCB8 /* AntForestController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A966E8C1EE048F60045FCB8 /* AntForestController.swift */; };
2425
1AB702661EA9A43C006DBA79 /* SecondViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB702651EA9A43C006DBA79 /* SecondViewController.swift */; };
2526
1AB702681EA9A9BC006DBA79 /* ThirdViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB702671EA9A9BC006DBA79 /* ThirdViewController.swift */; };
2627
1AB7026A1EA9AC7A006DBA79 /* FourthViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB702691EA9AC7A006DBA79 /* FourthViewController.swift */; };
@@ -62,6 +63,7 @@
6263
1A869EDE1ECAA36B006D96F8 /* CustomNavBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomNavBarController.swift; sourceTree = "<group>"; };
6364
1A96559B1ED6B64F00A89E30 /* CustomListController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomListController.swift; sourceTree = "<group>"; };
6465
1A96559D1ED6B8C600A89E30 /* MoveListController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoveListController.swift; sourceTree = "<group>"; };
66+
1A966E8C1EE048F60045FCB8 /* AntForestController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AntForestController.swift; sourceTree = "<group>"; };
6567
1AB702651EA9A43C006DBA79 /* SecondViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecondViewController.swift; sourceTree = "<group>"; };
6668
1AB702671EA9A9BC006DBA79 /* ThirdViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThirdViewController.swift; sourceTree = "<group>"; };
6769
1AB702691EA9AC7A006DBA79 /* FourthViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FourthViewController.swift; sourceTree = "<group>"; };
@@ -159,6 +161,7 @@
159161
1AB7026B1EA9B753006DBA79 /* FifthViewController.swift */,
160162
1AD014091EDBFB4500A6893C /* ZhiHuController.swift */,
161163
1AD014121EDC091F00A6893C /* QQMineController.swift */,
164+
1A966E8C1EE048F60045FCB8 /* AntForestController.swift */,
162165
);
163166
name = "普通";
164167
path = Demos;
@@ -385,6 +388,7 @@
385388
1A0DF7B51EA7380600191349 /* SixthViewController.swift in Sources */,
386389
1AB7026A1EA9AC7A006DBA79 /* FourthViewController.swift in Sources */,
387390
1A0DF77B1EA7176500191349 /* AppDelegate.swift in Sources */,
391+
1A966E8D1EE048F60045FCB8 /* AntForestController.swift in Sources */,
388392
1A96559C1ED6B64F00A89E30 /* CustomListController.swift in Sources */,
389393
1AB702661EA9A43C006DBA79 /* SecondViewController.swift in Sources */,
390394
1A0DF7B91EA7521C00191349 /* BaseNavigationController.swift in Sources */,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "WechatIMG52.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
34.9 KB
Loading
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
//
2+
// FourthViewController.swift
3+
// WRNavigationBar_swift
4+
//
5+
// Created by wangrui on 2017/4/21.
6+
// Copyright © 2017年 wangrui. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
private let NAVBAR_COLORCHANGE_POINT:CGFloat = -480
12+
private let IMAGE_HEIGHT:CGFloat = 480
13+
private let SCROLL_DOWN_LIMIT:CGFloat = 0
14+
private let LIMIT_OFFSET_Y:CGFloat = -(IMAGE_HEIGHT + SCROLL_DOWN_LIMIT)
15+
16+
class AntForestController: UIViewController
17+
{
18+
lazy var tableView:UITableView = {
19+
let table:UITableView = UITableView(frame: CGRect.init(x: 0, y: 0, width: kScreenWidth, height: self.view.bounds.height), style: .plain)
20+
table.contentInset = UIEdgeInsetsMake(IMAGE_HEIGHT-CGFloat(kNavBarBottom), 0, 0, 0);
21+
table.delegate = self
22+
table.dataSource = self
23+
return table
24+
}()
25+
lazy var imageView:UIImageView = {
26+
let imgView = UIImageView(frame: CGRect(x: 0, y: -IMAGE_HEIGHT, width: kScreenWidth, height: IMAGE_HEIGHT))
27+
imgView.contentMode = UIViewContentMode.scaleAspectFill
28+
imgView.clipsToBounds = true
29+
imgView.image = UIImage(named: "mysl")
30+
return imgView
31+
}()
32+
33+
override func viewDidLoad()
34+
{
35+
super.viewDidLoad()
36+
title = "蚂蚁森林"
37+
view.backgroundColor = UIColor.red
38+
tableView.addSubview(imageView)
39+
view.addSubview(tableView)
40+
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "··· ", style: .done, target: nil, action: nil)
41+
42+
43+
navBarBarTintColor = .white
44+
navBarBackgroundAlpha = 0
45+
}
46+
47+
deinit {
48+
tableView.delegate = nil
49+
print("FourthVC deinit")
50+
}
51+
}
52+
53+
// MARK: - viewWillAppear .. ScrollViewDidScroll
54+
extension AntForestController
55+
{
56+
func scrollViewDidScroll(_ scrollView: UIScrollView)
57+
{
58+
let offsetY = scrollView.contentOffset.y
59+
if (offsetY > NAVBAR_COLORCHANGE_POINT)
60+
{
61+
let alpha = (offsetY - NAVBAR_COLORCHANGE_POINT) / CGFloat(kNavBarBottom)
62+
navBarBackgroundAlpha = alpha
63+
if (alpha > 0.5) {
64+
navBarTintColor = UIColor(red: 0, green: 0.478431, blue: 1, alpha: 1.0)
65+
navBarTitleColor = .black
66+
statusBarStyle = .default
67+
} else {
68+
navBarTintColor = .white
69+
navBarTitleColor = .white
70+
statusBarStyle = .lightContent
71+
}
72+
}
73+
else
74+
{
75+
navBarBackgroundAlpha = 0
76+
navBarTintColor = .white
77+
navBarTitleColor = .white
78+
statusBarStyle = .lightContent
79+
}
80+
81+
82+
83+
84+
// 限制下拉距离
85+
if (offsetY < LIMIT_OFFSET_Y) {
86+
scrollView.contentOffset = CGPoint.init(x: 0, y: LIMIT_OFFSET_Y)
87+
}
88+
89+
// 改变图片框的大小 (上滑的时候不改变)
90+
// 这里不能使用offsetY,因为当(offsetY < LIMIT_OFFSET_Y)的时候,y = LIMIT_OFFSET_Y 不等于 offsetY
91+
let newOffsetY = scrollView.contentOffset.y
92+
if (newOffsetY < -IMAGE_HEIGHT)
93+
{
94+
imageView.frame = CGRect(x: 0, y: newOffsetY, width: kScreenWidth, height: -newOffsetY)
95+
}
96+
}
97+
}
98+
99+
100+
extension AntForestController: UITableViewDelegate,UITableViewDataSource
101+
{
102+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
103+
return 15
104+
}
105+
106+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
107+
{
108+
let cell = UITableViewCell.init(style: .default, reuseIdentifier: nil)
109+
let str = String(format: "WRNavigationBar %zd", indexPath.row)
110+
cell.textLabel?.text = str
111+
cell.textLabel?.font = UIFont.systemFont(ofSize: 15)
112+
return cell
113+
}
114+
115+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
116+
{
117+
tableView.deselectRow(at: indexPath, animated: true)
118+
let vc:UIViewController = UIViewController()
119+
vc.view.backgroundColor = UIColor.white
120+
let str = String(format: "WRNavigationBar %zd", indexPath.row)
121+
vc.title = str
122+
navigationController?.pushViewController(vc, animated: true)
123+
}
124+
}

WRNavigationBar_swift/WRNavigationBar_swift/Demos/NormalListController.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ extension NormalListController: UITableViewDelegate, UITableViewDataSource
5050
str = "知乎日报"
5151
case 4:
5252
str = "QQ我的资料页"
53+
case 5:
54+
str = "蚂蚁森林"
5355
default:
5456
str = ""
5557
}
@@ -76,6 +78,8 @@ extension NormalListController: UITableViewDelegate, UITableViewDataSource
7678
navigationController?.pushViewController(ZhiHuController(), animated: true)
7779
case 4:
7880
navigationController?.pushViewController(QQMineController(), animated: true)
81+
case 5:
82+
navigationController?.pushViewController(AntForestController(), animated: true)
7983
default:
8084
break
8185
}

0 commit comments

Comments
 (0)