Commit 4947c6d943c3ebbe243f28289affd172ef4dd631

Authored by Cao yang
1 parent 1ad8d946
Exists in parentassistant

适配布局,优化操作体验

ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate
No preview for this file type
ParentAssistant/ParentAssistant/Classes/controllers/Grow/GrowViewController.swift
@@ -51,11 +51,11 @@ class GrowViewController: UIViewController,UIScrollViewDelegate { @@ -51,11 +51,11 @@ class GrowViewController: UIViewController,UIScrollViewDelegate {
51 view.addSubview(imageView) 51 view.addSubview(imageView)
52 return view 52 return view
53 }() 53 }()
54 - 54 + //导航栏左侧按钮
55 var titleLeftLab = UILabel() 55 var titleLeftLab = UILabel()
56 -  
57 - var childDataModel = StudentClassInfoModel()  
58 - 56 + //当前显示的控制器
  57 + var nowIndex = 0
  58 +
59 //是否显示右侧按钮 59 //是否显示右侧按钮
60 var rightBtn = UIBarButtonItem() 60 var rightBtn = UIBarButtonItem()
61 61
@@ -94,12 +94,10 @@ class GrowViewController: UIViewController,UIScrollViewDelegate { @@ -94,12 +94,10 @@ class GrowViewController: UIViewController,UIScrollViewDelegate {
94 maker.centerX.equalTo((CGFloat(i)+0.5)*width) 94 maker.centerX.equalTo((CGFloat(i)+0.5)*width)
95 maker.centerY.equalTo(contentScrollView) 95 maker.centerY.equalTo(contentScrollView)
96 } 96 }
97 -  
98 - print("childView Frame=\(vc.view.frame)")  
99 } 97 }
100 //设置scrollview滑动范围 98 //设置scrollview滑动范围
101 contentScrollView.contentSize = CGSize.init(width: width*CGFloat(titleArr.count), height: 0) 99 contentScrollView.contentSize = CGSize.init(width: width*CGFloat(titleArr.count), height: 0)
102 -// contentScrollView.setContentOffset(CGPoint.init(x: 0, y: 0), animated: true) 100 + contentScrollView.setContentOffset(CGPoint.init(x: CGFloat(nowIndex)*width, y: 0), animated: true)
103 } 101 }
104 102
105 override func viewWillAppear(_ animated: Bool) { 103 override func viewWillAppear(_ animated: Bool) {
@@ -273,26 +271,7 @@ class GrowViewController: UIViewController,UIScrollViewDelegate { @@ -273,26 +271,7 @@ class GrowViewController: UIViewController,UIScrollViewDelegate {
273 let index = CGFloat(btn.tag) 271 let index = CGFloat(btn.tag)
274 272
275 if contentScrollView.contentSize.width>0 { 273 if contentScrollView.contentSize.width>0 {
276 -  
277 -// let childVC = self.childViewControllers[btn.tag]  
278 contentScrollView.setContentOffset(CGPoint.init(x: index*contentScrollView.bounds.size.width, y: 0), animated: true) 274 contentScrollView.setContentOffset(CGPoint.init(x: index*contentScrollView.bounds.size.width, y: 0), animated: true)
279 -  
280 -// if self.contentScrollView.subviews.contains(childVC.view){  
281 -// //已有view,直接移动  
282 -// //移动scrollview  
283 -// viewDidLayoutSubviews()  
284 -// contentScrollView.setContentOffset(CGPoint.init(x: index*contentScrollView.bounds.size.width, y: 0), animated: true)  
285 -// }else{  
286 -// //新加view,刷新数据  
287 -// self.contentScrollView.addSubview(childVC.view)  
288 -// childVC.view.snp.makeConstraints { (maker) in  
289 -// maker.width.height.equalTo(self.contentScrollView)  
290 -// maker.centerX.equalTo((index+0.5)*contentScrollView.bounds.size.width)  
291 -// maker.centerY.equalTo(self.contentScrollView)  
292 -// }  
293 -// //移动scrollview  
294 -// contentScrollView.setContentOffset(CGPoint.init(x: index*screenWidth, y: 0), animated: true)  
295 -// }  
296 } 275 }
297 if btn.tag == 0 { 276 if btn.tag == 0 {
298 self.navigationItem.rightBarButtonItem = nil 277 self.navigationItem.rightBarButtonItem = nil
@@ -301,11 +280,22 @@ class GrowViewController: UIViewController,UIScrollViewDelegate { @@ -301,11 +280,22 @@ class GrowViewController: UIViewController,UIScrollViewDelegate {
301 } 280 }
302 } 281 }
303 //MARK: - ScrollView Delegate 282 //MARK: - ScrollView Delegate
  283 + func scrollViewDidScroll(_ scrollView: UIScrollView) {
  284 + let vc = self.childViewControllers[1] as! ReportViewController
  285 + scrollView.isScrollEnabled = vc.calendar.isHidden
  286 + vc.calendar.backBlock = {
  287 + DebugLog("日期消失,解除滑动锁定!")
  288 + scrollView.isScrollEnabled = true
  289 + }
  290 + }
  291 +
304 func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { 292 func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
305 293
306 if scrollView == contentScrollView { 294 if scrollView == contentScrollView {
307 let offsetX = scrollView.contentOffset.x 295 let offsetX = scrollView.contentOffset.x
308 let index = Int(offsetX/getScreenWidth()) 296 let index = Int(offsetX/getScreenWidth())
  297 + //标记当前位置
  298 + nowIndex = index
309 let btn = titleBtnArr[index] 299 let btn = titleBtnArr[index]
310 clickTitleAction(btn: btn) 300 clickTitleAction(btn: btn)
311 } 301 }
ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/MoralViewController.swift
@@ -12,7 +12,7 @@ class MoralViewController: UIViewController,UITableViewDelegate,UITableViewDataS @@ -12,7 +12,7 @@ class MoralViewController: UIViewController,UITableViewDelegate,UITableViewDataS
12 12
13 lazy var tableView = {()->UITableView in 13 lazy var tableView = {()->UITableView in
14 14
15 - let table = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: screenWidth, height: screenHeight-navigationBarHeight!-statusBarHeight-10)) 15 + let table = UITableView.init(frame: self.view.bounds)
16 table.backgroundColor = backGroundColor 16 table.backgroundColor = backGroundColor
17 table.delegate = self 17 table.delegate = self
18 table.dataSource = self 18 table.dataSource = self
@@ -30,8 +30,12 @@ class MoralViewController: UIViewController,UITableViewDelegate,UITableViewDataS @@ -30,8 +30,12 @@ class MoralViewController: UIViewController,UITableViewDelegate,UITableViewDataS
30 self.title = "德育报告" 30 self.title = "德育报告"
31 self.view.backgroundColor = backGroundColor 31 self.view.backgroundColor = backGroundColor
32 self.view.addSubview(self.tableView) 32 self.view.addSubview(self.tableView)
33 -  
34 - 33 + tableView.snp.makeConstraints { (maker) in
  34 + maker.width.equalToSuperview()
  35 + maker.bottom.equalToSuperview()
  36 + maker.top.equalToSuperview()
  37 + maker.centerX.equalToSuperview()
  38 + }
35 downLoadDataFromNet() 39 downLoadDataFromNet()
36 } 40 }
37 41
ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/ReportViewController.swift
@@ -39,13 +39,24 @@ class ReportViewController: UIViewController,UITableViewDelegate,UITableViewData @@ -39,13 +39,24 @@ class ReportViewController: UIViewController,UITableViewDelegate,UITableViewData
39 self.view.addSubview(self.reportTable) 39 self.view.addSubview(self.reportTable)
40 reportTable.snp.makeConstraints { (maker) in 40 reportTable.snp.makeConstraints { (maker) in
41 maker.width.equalToSuperview() 41 maker.width.equalToSuperview()
42 - maker.height.equalTo(self.view.frame.size.height-60-44) 42 + maker.bottom.equalToSuperview()
43 maker.top.equalTo(60) 43 maker.top.equalTo(60)
44 maker.centerX.equalToSuperview() 44 maker.centerX.equalToSuperview()
45 } 45 }
  46 +
  47 + calendar = CalendarView.init(frame: CGRect.init(x: 0, y: 0, width: screenWidth, height: 245))
  48 + self.view.addSubview(calendar)
  49 + calendar.snp.makeConstraints { (maker) in
  50 + maker.width.equalToSuperview()
  51 + maker.height.equalTo(245)
  52 + maker.centerX.equalToSuperview()
  53 + maker.top.equalTo(headView)
  54 + }
  55 + calendar.isHidden = true
46 } 56 }
47 override func viewDidLayoutSubviews() { 57 override func viewDidLayoutSubviews() {
48 - 58 + DebugLog("横屏")
  59 + DebugLog(self.view.frame.height)
49 } 60 }
50 61
51 // MARK: - 设置日期View 62 // MARK: - 设置日期View
@@ -63,9 +74,7 @@ class ReportViewController: UIViewController,UITableViewDelegate,UITableViewData @@ -63,9 +74,7 @@ class ReportViewController: UIViewController,UITableViewDelegate,UITableViewData
63 let recognizer = UISwipeGestureRecognizer.init(target: self, action: #selector(showView)) 74 let recognizer = UISwipeGestureRecognizer.init(target: self, action: #selector(showView))
64 recognizer.direction = UISwipeGestureRecognizerDirection.down 75 recognizer.direction = UISwipeGestureRecognizerDirection.down
65 headView.addGestureRecognizer(recognizer) 76 headView.addGestureRecognizer(recognizer)
66 -  
67 - calendar = CalendarView.init(frame: CGRect.init(x: 0, y: y*2, width: screenWidth, height: 245))  
68 - 77 +
69 } 78 }
70 79
71 @objc func showView(){ 80 @objc func showView(){
ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/SceneDetailViewController.swift
@@ -11,7 +11,7 @@ import UIKit @@ -11,7 +11,7 @@ import UIKit
11 class SceneDetailViewController: UIViewController,UITableViewDataSource,UITableViewDelegate { 11 class SceneDetailViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
12 12
13 lazy var sceneTableView = {()->UITableView in 13 lazy var sceneTableView = {()->UITableView in
14 - let table = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: screenWidth, height: screenHeight-navigationBarHeight!-statusBarHeight-10)) 14 + let table = UITableView.init(frame: self.view.bounds)
15 table.backgroundColor = backGroundColor 15 table.backgroundColor = backGroundColor
16 table.delegate = self 16 table.delegate = self
17 table.dataSource = self 17 table.dataSource = self
@@ -28,7 +28,12 @@ class SceneDetailViewController: UIViewController,UITableViewDataSource,UITableV @@ -28,7 +28,12 @@ class SceneDetailViewController: UIViewController,UITableViewDataSource,UITableV
28 self.title = "场景详情" 28 self.title = "场景详情"
29 self.view.backgroundColor = backGroundColor 29 self.view.backgroundColor = backGroundColor
30 self.view.addSubview(self.sceneTableView) 30 self.view.addSubview(self.sceneTableView)
31 - 31 + sceneTableView.snp.makeConstraints { (maker) in
  32 + maker.width.equalToSuperview()
  33 + maker.bottom.equalToSuperview()
  34 + maker.top.equalToSuperview()
  35 + maker.centerX.equalToSuperview()
  36 + }
32 } 37 }
33 func numberOfSections(in tableView: UITableView) -> Int { 38 func numberOfSections(in tableView: UITableView) -> Int {
34 return 3 39 return 3
ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/CalendarView.swift
@@ -10,6 +10,9 @@ import UIKit @@ -10,6 +10,9 @@ import UIKit
10 10
11 class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { 11 class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
12 12
  13 + ///通知父控制器解除滑动限制
  14 + typealias CloseWindowBlock = ()->()
  15 +
13 var keyWindow = UIWindow() 16 var keyWindow = UIWindow()
14 var backBtn = UIButton() 17 var backBtn = UIButton()
15 var topBtn = UIButton() 18 var topBtn = UIButton()
@@ -18,10 +21,23 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { @@ -18,10 +21,23 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
18 var monthDay = Int() 21 var monthDay = Int()
19 var todayDay = Int() 22 var todayDay = Int()
20 23
  24 + var viewWidth = CGFloat()
  25 + var viewHeight = CGFloat()
  26 +
  27 + var backBlock : CloseWindowBlock?
  28 +
  29 +
21 override init(frame: CGRect) { 30 override init(frame: CGRect) {
22 super.init(frame: frame) 31 super.init(frame: frame)
23 if !frame.isEmpty{ 32 if !frame.isEmpty{
  33 + viewWidth = frame.width
  34 + viewWidth = frame.height
  35 + self.backgroundColor = UIColor.orange
24 self.addSubview(self.collectionView) 36 self.addSubview(self.collectionView)
  37 + collectionView.snp.makeConstraints { (maker) in
  38 + maker.center.equalToSuperview()
  39 + maker.height.width.equalToSuperview()
  40 + }
25 firstDay = CalendarDateManager.shared.getFirstMonthDays() 41 firstDay = CalendarDateManager.shared.getFirstMonthDays()
26 monthDay = CalendarDateManager.shared.getCurrentMonthDay() 42 monthDay = CalendarDateManager.shared.getCurrentMonthDay()
27 todayDay = CalendarDateManager.shared.getTodayDate() 43 todayDay = CalendarDateManager.shared.getTodayDate()
@@ -30,11 +46,15 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { @@ -30,11 +46,15 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
30 override func layoutSubviews() { 46 override func layoutSubviews() {
31 47
32 self.flowlayOut.itemSize = CGSize.init(width: self.bounds.size.width/7, height: 35) 48 self.flowlayOut.itemSize = CGSize.init(width: self.bounds.size.width/7, height: 35)
  49 + viewWidth = self.bounds.size.width
  50 + viewHeight = self.bounds.size.height
  51 +
33 } 52 }
  53 +
34 lazy var flowlayOut = {()-> UICollectionViewFlowLayout in 54 lazy var flowlayOut = {()-> UICollectionViewFlowLayout in
35 //设置layout 55 //设置layout
36 let flowlayout = UICollectionViewFlowLayout() 56 let flowlayout = UICollectionViewFlowLayout()
37 - flowlayout.itemSize = CGSize.init(width: self.bounds.size.width/7, height:35) 57 + flowlayout.itemSize = CGSize.init(width: viewWidth/7, height:35)
38 flowlayout.minimumLineSpacing = 0 58 flowlayout.minimumLineSpacing = 0
39 flowlayout.minimumInteritemSpacing = 0 59 flowlayout.minimumInteritemSpacing = 0
40 flowlayout.headerReferenceSize = CGSize.init(width: 0, height: 0) 60 flowlayout.headerReferenceSize = CGSize.init(width: 0, height: 0)
@@ -45,7 +65,7 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { @@ -45,7 +65,7 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
45 65
46 lazy var collectionView = {()-> UICollectionView in 66 lazy var collectionView = {()-> UICollectionView in
47 67
48 - let calendarView = UICollectionView.init(frame: self.bounds, collectionViewLayout: flowlayOut) 68 + let calendarView = UICollectionView.init(frame: self.bounds, collectionViewLayout: self.flowlayOut)
49 calendarView.delegate = self 69 calendarView.delegate = self
50 calendarView.dataSource = self 70 calendarView.dataSource = self
51 calendarView.backgroundColor = UIColor.white 71 calendarView.backgroundColor = UIColor.white
@@ -59,19 +79,27 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { @@ -59,19 +79,27 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
59 79
60 let key = UIApplication.shared.keyWindow! 80 let key = UIApplication.shared.keyWindow!
61 81
62 - let top = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: self.bounds.size.width, height: self.frame.origin.y)) 82 + let top = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: viewWidth, height: statusBarHeight+navigationBarHeight!))
63 top.backgroundColor = UIColor.clear 83 top.backgroundColor = UIColor.clear
64 - top.addTarget(self, action: #selector(closeView(btn:)), for: UIControlEvents.allEvents) 84 + top.addTarget(self, action: #selector(closeView), for: UIControlEvents.allEvents)
65 85
66 - let back = UIButton.init(frame: CGRect.init(x: 0, y: self.bounds.size.height, width: screenWidth, height: screenHeight)) 86 + let back = UIButton.init(frame: CGRect.init(x: 0, y: viewHeight+statusBarHeight+navigationBarHeight!, width: viewWidth, height: screenHeight*2))
67 back.backgroundColor = UIColor.black 87 back.backgroundColor = UIColor.black
68 back.alpha = 0.4 88 back.alpha = 0.4
69 - back.addTarget(self, action: #selector(closeView(btn:)), for: UIControlEvents.allEvents) 89 + back.addTarget(self, action: #selector(closeView), for: UIControlEvents.allEvents)
70 90
71 key.addSubview(top) 91 key.addSubview(top)
72 key.addSubview(back) 92 key.addSubview(back)
73 - key.addSubview(self)  
74 - 93 + top.snp.makeConstraints { (maker) in
  94 + maker.width.equalToSuperview()
  95 + maker.height.equalTo(statusBarHeight+navigationBarHeight!)
  96 + maker.top.equalToSuperview()
  97 + }
  98 + back.snp.makeConstraints { (maker) in
  99 + maker.width.equalToSuperview()
  100 + maker.height.equalToSuperview()
  101 + maker.top.equalTo(viewHeight+statusBarHeight+navigationBarHeight!)
  102 + }
75 self.isHidden = false 103 self.isHidden = false
76 keyWindow = key 104 keyWindow = key
77 backBtn = back 105 backBtn = back
@@ -79,14 +107,14 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { @@ -79,14 +107,14 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
79 107
80 } 108 }
81 //MARK: - 关闭视图 109 //MARK: - 关闭视图
82 - @objc func closeView(btn:UIButton) { 110 + @objc private func closeView() {
  111 +
  112 + self.backBlock!()
  113 + self.backBtn.removeFromSuperview()
  114 + self.topBtn.removeFromSuperview()
  115 + self.keyWindow = UIWindow.init()
  116 + self.isHidden = true
83 117
84 - UIView.animate(withDuration: 0.3) {  
85 - self.backBtn.removeFromSuperview()  
86 - self.topBtn.removeFromSuperview()  
87 - self.keyWindow = UIWindow.init()  
88 - self.isHidden = true  
89 - }  
90 } 118 }
91 119
92 //MARK: - Delegate 120 //MARK: - Delegate
@@ -98,7 +126,6 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { @@ -98,7 +126,6 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
98 126
99 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "calendarCell", for: indexPath) 127 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "calendarCell", for: indexPath)
100 let lab = UILabel.init(frame: cell.bounds) 128 let lab = UILabel.init(frame: cell.bounds)
101 -  
102 if indexPath.row < weekLab.count { 129 if indexPath.row < weekLab.count {
103 lab.text = weekLab[indexPath.row] 130 lab.text = weekLab[indexPath.row]
104 }else{ 131 }else{
@@ -121,6 +148,10 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { @@ -121,6 +148,10 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
121 148
122 lab.textAlignment = .center 149 lab.textAlignment = .center
123 cell.addSubview(lab) 150 cell.addSubview(lab)
  151 + lab.snp.makeConstraints { (maker) in
  152 + maker.center.equalToSuperview()
  153 + maker.height.width.equalToSuperview()
  154 + }
124 return cell 155 return cell
125 156
126 } 157 }
ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/SceneMiddleCell.swift
@@ -32,7 +32,12 @@ class SceneMiddleCell: UITableViewCell { @@ -32,7 +32,12 @@ class SceneMiddleCell: UITableViewCell {
32 customLineChart.drawLine(point: arr3, color: UIColorWithRGB(R: 255, G: 213, B: 79)) 32 customLineChart.drawLine(point: arr3, color: UIColorWithRGB(R: 255, G: 213, B: 79))
33 33
34 self.addSubview(customLineChart) 34 self.addSubview(customLineChart)
35 - 35 + customLineChart.snp.makeConstraints { (maker) in
  36 + maker.top.equalTo(60)
  37 + maker.left.equalTo(20)
  38 + maker.right.equalTo(20)
  39 + maker.bottom.equalToSuperview()
  40 + }
36 } 41 }
37 42
38 override func setSelected(_ selected: Bool, animated: Bool) { 43 override func setSelected(_ selected: Bool, animated: Bool) {