forked from zpz1237/NirZhihuDaily2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SideMenuViewController.swift
100 lines (86 loc) · 3.9 KB
/
SideMenuViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// SideMenuViewController.swift
// zhihuDaily 2.0
//
// Created by Nirvana on 10/12/15.
// Copyright © 2015 NSNirvana. All rights reserved.
//
import UIKit
class SideMenuViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
var blurView: GradientView!
var originState = true {
didSet {
if oldValue != originState {
self.tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)], withRowAnimation: .None)
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
//添加最后一行的遮罩层
blurView = GradientView(frame: CGRectMake(0, self.view.frame.height - 45 - 50, self.view.frame.width, 50), type: TRANSPARENT_ANOTHER_GRADIENT_TYPE)
self.view.addSubview(blurView)
//tableView以及父view的基础设置
self.view.backgroundColor = UIColor(red: 19/255.0, green: 26/255.0, blue: 32/255.0, alpha: 1)
self.tableView.backgroundColor = UIColor(red: 19/255.0, green: 26/255.0, blue: 32/255.0, alpha: 1)
self.tableView.separatorStyle = .None
self.tableView.showsVerticalScrollIndicator = false
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.rowHeight = 50.5
}
//获取总代理
func appCloud() -> AppDelegate {
return UIApplication.sharedApplication().delegate as! AppDelegate
}
//更改StatusBar颜色
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//tableViewDataSource和Delegate
extension SideMenuViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return appCloud().themes.count + 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCellWithIdentifier("homeSideCell") as! HomeSideCell
if originState == false {
cell.contentView.backgroundColor = UIColor(red: 19/255.0, green: 26/255.0, blue: 32/255.0, alpha: 1)
cell.homeImageView.tintColor = UIColor(red: 136/255.0, green: 141/255.0, blue: 145/255.0, alpha: 1)
cell.homeTitleLabel.textColor = UIColor(red: 136/255.0, green: 141/255.0, blue: 145/255.0, alpha: 1)
}
return cell
}
let cell = tableView.dequeueReusableCellWithIdentifier("contentSideCell") as! ContentSideCell
cell.contentTitleLabel.text = appCloud().themes[indexPath.row - 1].name
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//初始状态结束 回归正常UI搭配
if let _ = tableView.cellForRowAtIndexPath(indexPath) as? ContentSideCell {
originState = false
}
//初始状态结束 回归正常UI搭配 且协助设置选中状态UI
if let cell = tableView.cellForRowAtIndexPath(indexPath) as? HomeSideCell {
originState = false
cell.homeImageView.tintColor = UIColor.whiteColor()
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
//判定是否转场到主题日报文章列表
if let nav = segue.destinationViewController as? UINavigationController {
if let vc = nav.topViewController as? ThemeViewController {
let index = self.tableView.indexPathForSelectedRow!.row
vc.name = appCloud().themes[index - 1].name
vc.id = appCloud().themes[index - 1].id
}
}
}
}