Skip to content

Commit fa22e84

Browse files
committed
更改项目结构,修复多项bug
1 parent 38fafce commit fa22e84

35 files changed

+1182
-760
lines changed
File renamed without changes.

Demo/Assets.xcassets/Contents.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
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" : "tiercel.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+
}
Loading

Example/Example/Base.lproj/LaunchScreen.storyboard renamed to Demo/Base.lproj/LaunchScreen.storyboard

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<dependencies>
77
<deployment identifier="iOS"/>
88
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
9+
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
910
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
1011
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1112
</dependencies>
@@ -34,11 +35,20 @@
3435
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
3536
<nil key="highlightedColor"/>
3637
</label>
38+
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="tiercel" translatesAutoresizingMaskIntoConstraints="NO" id="Xs0-G4-dgv">
39+
<rect key="frame" x="37" y="169.5" width="300" height="127.5"/>
40+
<constraints>
41+
<constraint firstAttribute="width" secondItem="Xs0-G4-dgv" secondAttribute="height" multiplier="567:241" id="PBu-r2-yXM"/>
42+
<constraint firstAttribute="width" constant="300" id="lqo-aN-Nyx"/>
43+
</constraints>
44+
</imageView>
3745
</subviews>
3846
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3947
<constraints>
48+
<constraint firstItem="Xs0-G4-dgv" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="4FF-0D-3kZ"/>
4049
<constraint firstItem="Crr-yi-J63" firstAttribute="top" secondItem="8Pb-cT-Hex" secondAttribute="bottom" constant="20" id="VfN-q8-nEO"/>
4150
<constraint firstItem="qJv-w8-Bvf" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="ayL-Av-Kst"/>
51+
<constraint firstItem="Xs0-G4-dgv" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" multiplier="0.7" id="fB7-wU-L0S"/>
4252
<constraint firstItem="8Pb-cT-Hex" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="zcs-zK-K2p"/>
4353
<constraint firstItem="qJv-w8-Bvf" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" multiplier="2/3" id="zln-UZ-fv0"/>
4454
</constraints>
@@ -49,4 +59,7 @@
4959
<point key="canvasLocation" x="53" y="375"/>
5060
</scene>
5161
</scenes>
62+
<resources>
63+
<image name="tiercel" width="2268" height="964"/>
64+
</resources>
5265
</document>

Example/Example/Base.lproj/Main.storyboard renamed to Demo/Base.lproj/Main.storyboard

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
<!--View Controller1-->
147147
<scene sceneID="qBW-vF-vcc">
148148
<objects>
149-
<viewController id="hzf-Gg-ctm" customClass="ViewController1" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
149+
<viewController id="hzf-Gg-ctm" customClass="ViewController1" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController">
150150
<layoutGuides>
151151
<viewControllerLayoutGuide type="top" id="FBA-3L-RWo"/>
152152
<viewControllerLayoutGuide type="bottom" id="gCe-UX-hK9"/>
@@ -273,7 +273,7 @@
273273
<!--Tab Bar Controller-->
274274
<scene sceneID="4Mr-XD-9eV">
275275
<objects>
276-
<tabBarController id="DqQ-cC-dJm" sceneMemberID="viewController">
276+
<tabBarController automaticallyAdjustsScrollViewInsets="NO" id="DqQ-cC-dJm" sceneMemberID="viewController">
277277
<tabBar key="tabBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="c1E-8K-Zhv">
278278
<rect key="frame" x="0.0" y="0.0" width="375" height="49"/>
279279
<autoresizingMask key="autoresizingMask"/>
@@ -291,13 +291,13 @@
291291
<!--List View Controller-->
292292
<scene sceneID="GKI-k7-WFW">
293293
<objects>
294-
<tableViewController id="OQp-GJ-mes" customClass="ListViewController" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
294+
<tableViewController id="OQp-GJ-mes" customClass="ListViewController" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController">
295295
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="5Tg-ts-YaN">
296296
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
297297
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
298298
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
299299
<prototypes>
300-
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="listCell" id="xrT-VF-286" customClass="ListViewCell" customModule="Example" customModuleProvider="target">
300+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="listCell" id="xrT-VF-286" customClass="ListViewCell" customModule="Demo" customModuleProvider="target">
301301
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
302302
<autoresizingMask key="autoresizingMask"/>
303303
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="xrT-VF-286" id="wKO-lA-kkM">
@@ -345,7 +345,7 @@
345345
<!--View Controller3-->
346346
<scene sceneID="spu-eN-Uq5">
347347
<objects>
348-
<viewController id="WS1-bt-7kH" customClass="ViewController3" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
348+
<viewController id="WS1-bt-7kH" customClass="ViewController3" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController">
349349
<layoutGuides>
350350
<viewControllerLayoutGuide type="top" id="Inf-bO-w9M"/>
351351
<viewControllerLayoutGuide type="bottom" id="cMq-08-pfT"/>
@@ -499,7 +499,7 @@
499499
<!--View Controller2-->
500500
<scene sceneID="dgf-g9-GoM">
501501
<objects>
502-
<viewController id="wVe-jT-pWR" customClass="ViewController2" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
502+
<viewController id="wVe-jT-pWR" customClass="ViewController2" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController">
503503
<layoutGuides>
504504
<viewControllerLayoutGuide type="top" id="ePF-bI-QPJ"/>
505505
<viewControllerLayoutGuide type="bottom" id="4hD-15-YYs"/>
@@ -662,7 +662,7 @@
662662
<!--Download View Controller-->
663663
<scene sceneID="O5P-xU-gvw">
664664
<objects>
665-
<viewController id="RE7-91-rUf" customClass="DownloadViewController" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
665+
<viewController id="RE7-91-rUf" customClass="DownloadViewController" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController">
666666
<layoutGuides>
667667
<viewControllerLayoutGuide type="top" id="98g-RD-IbM"/>
668668
<viewControllerLayoutGuide type="bottom" id="6dG-As-YWr"/>

Example/Example/BaseViewController.swift renamed to Demo/BaseViewController.swift

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import UIKit
10+
import Tiercel
1011

1112
class BaseViewController: UIViewController {
1213

@@ -52,13 +53,48 @@ class BaseViewController: UIViewController {
5253

5354
}
5455

55-
56+
func setupManager() {
57+
58+
// 设置manager的回调
59+
downloadManager?.progress { [weak self] (manager) in
60+
guard let strongSelf = self else { return }
61+
strongSelf.updateUI()
62+
63+
}.success{ [weak self] (manager) in
64+
guard let strongSelf = self else { return }
65+
strongSelf.updateUI()
66+
if manager.status == .suspend {
67+
// manager 暂停了
68+
}
69+
if manager.status == .completed {
70+
// manager 完成了
71+
}
72+
}.failure { [weak self] (manager) in
73+
guard let strongSelf = self,
74+
let downloadManager = strongSelf.downloadManager
75+
else { return }
76+
strongSelf.downloadURLStrings = downloadManager.tasks.map({ $0.URLString })
77+
strongSelf.tableView.reloadData()
78+
strongSelf.updateUI()
79+
80+
if manager.status == .failed {
81+
// manager 失败了
82+
}
83+
if manager.status == .cancel {
84+
// manager 取消了
85+
}
86+
if manager.status == .remove {
87+
// manager 移除了
88+
}
89+
}
90+
}
5691
}
5792

5893
extension BaseViewController {
5994
@IBAction func totalStart(_ sender: Any) {
6095
downloadManager?.isStartDownloadImmediately = true
6196
downloadManager?.totalStart()
97+
tableView.reloadData()
6298
}
6399

64100
@IBAction func totalSuspend(_ sender: Any) {
@@ -106,7 +142,7 @@ extension BaseViewController: UITableViewDataSource, UITableViewDelegate {
106142
switch task.status {
107143
case .running:
108144
image = #imageLiteral(resourceName: "resume")
109-
case .suspend, .completed:
145+
case .suspend, .completed, .waiting:
110146
image = #imageLiteral(resourceName: "suspend")
111147
default: break
112148
}
@@ -149,10 +185,26 @@ extension BaseViewController: UITableViewDataSource, UITableViewDelegate {
149185
.success({ [weak cell] (task) in
150186
guard let cell = cell as? DownloadTaskCell else { return }
151187
cell.controlButton.setImage(#imageLiteral(resourceName: "suspend"), for: .normal)
188+
if task.status == .suspend {
189+
// 下载任务暂停了
190+
}
191+
if task.status == .completed {
192+
// 下载任务完成了
193+
}
152194
})
153195
.failure({ [weak cell] (task) in
154196
guard let cell = cell as? DownloadTaskCell else { return }
155197
cell.controlButton.setImage(#imageLiteral(resourceName: "suspend"), for: .normal)
198+
199+
if task.status == .failed {
200+
// 下载任务失败了
201+
}
202+
if task.status == .cancel {
203+
// 下载任务取消了
204+
}
205+
if task.status == .remove {
206+
// 下载任务移除了
207+
}
156208
})
157209
}
158210

Example/Example/DownloadTaskCell.swift renamed to Demo/DownloadTaskCell.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import UIKit
10+
import Tiercel
1011

1112
class DownloadTaskCell: UITableViewCell {
1213

File renamed without changes.

Example/Example/DownloadViewController.swift renamed to Demo/DownloadViewController.swift

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,13 @@ class DownloadViewController: BaseViewController {
1313

1414
override func viewDidLoad() {
1515
super.viewDidLoad()
16+
1617
downloadManager = ListViewController.downloadManager
1718

1819
// 因为会读取缓存到沙盒的任务,所以第一次的时候,不要马上开始下载
1920
downloadManager?.isStartDownloadImmediately = false
2021

21-
guard let downloadManager = downloadManager else { return }
22-
23-
// 设置manager的回调
24-
downloadManager.progress { [weak self] (manager) in
25-
guard let strongSelf = self else { return }
26-
strongSelf.updateUI()
27-
}.success{ [weak self] (manager) in
28-
guard let strongSelf = self else { return }
29-
strongSelf.updateUI()
30-
}.failure { [weak self] (manager) in
31-
guard let strongSelf = self,
32-
let downloadManager = strongSelf.downloadManager
33-
else { return }
34-
strongSelf.downloadURLStrings = downloadManager.tasks.map({ $0.URLString })
35-
strongSelf.tableView.reloadData()
36-
strongSelf.updateUI()
37-
}
22+
setupManager()
3823

3924
}
4025

@@ -55,13 +40,13 @@ extension DownloadViewController {
5540
@IBAction func deleteDownloadTask(_ sender: Any) {
5641
guard let downloadManager = downloadManager else { return }
5742
let count = downloadManager.tasks.count
43+
guard count > 0 else { return }
44+
5845
let index = downloadManager.tasks.count - 1
59-
if count > 0 {
60-
let URLString = downloadURLStrings[index]
61-
downloadURLStrings.remove(at: index)
62-
tableView.deleteRows(at: [IndexPath(row: index, section: 0)], with: .automatic)
63-
downloadManager.remove(URLString, completely: false)
64-
}
46+
let URLString = downloadURLStrings[index]
47+
downloadURLStrings.remove(at: index)
48+
tableView.deleteRows(at: [IndexPath(row: index, section: 0)], with: .automatic)
49+
downloadManager.remove(URLString, completely: false)
6550
updateUI()
6651
}
6752

File renamed without changes.
File renamed without changes.

Example/Example/ListViewController.swift renamed to Demo/ListViewController.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import UIKit
10+
import Tiercel
1011

1112
class ListViewController: UITableViewController {
1213

@@ -18,7 +19,12 @@ class ListViewController: UITableViewController {
1819

1920
override func viewDidLoad() {
2021
super.viewDidLoad()
21-
22+
if #available(iOS 11, *) {
23+
} else {
24+
tableView.contentInset.top = 64
25+
tableView.scrollIndicatorInsets.top = 64
26+
}
27+
2228
}
2329

2430

Example/Example/ViewController1.swift renamed to Demo/ViewController1.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import UIKit
10+
import Tiercel
1011

1112
class ViewController1: UIViewController {
1213

@@ -43,13 +44,32 @@ class ViewController1: UIViewController {
4344
}
4445

4546
@IBAction func start(_ sender: UIButton) {
47+
4648
downloadManager.download(URLString, fileName: "小黄人.mp4", progressHandler: { [weak self] (task) in
4749
self?.updateUI(task)
4850
}, successHandler: { [weak self] (task) in
4951
self?.updateUI(task)
50-
}) { [weak self] (task) in
52+
if task.status == .suspend {
53+
// 下载任务暂停了
54+
}
55+
56+
if task.status == .completed {
57+
// 下载任务完成了
58+
}
59+
}, failureHandler: { [weak self] (task) in
5160
self?.updateUI(task)
52-
}
61+
if task.status == .failed {
62+
// 下载任务失败了
63+
}
64+
65+
if task.status == .cancel {
66+
// 下载任务取消了
67+
}
68+
69+
if task.status == .remove {
70+
// 下载任务移除了
71+
}
72+
})
5373
}
5474

5575
@IBAction func suspend(_ sender: UIButton) {

0 commit comments

Comments
 (0)