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 51 view.addSubview(imageView)
52 52 return view
53 53 }()
54   -
  54 + //导航栏左侧按钮
55 55 var titleLeftLab = UILabel()
56   -
57   - var childDataModel = StudentClassInfoModel()
58   -
  56 + //当前显示的控制器
  57 + var nowIndex = 0
  58 +
59 59 //是否显示右侧按钮
60 60 var rightBtn = UIBarButtonItem()
61 61  
... ... @@ -94,12 +94,10 @@ class GrowViewController: UIViewController,UIScrollViewDelegate {
94 94 maker.centerX.equalTo((CGFloat(i)+0.5)*width)
95 95 maker.centerY.equalTo(contentScrollView)
96 96 }
97   -
98   - print("childView Frame=\(vc.view.frame)")
99 97 }
100 98 //设置scrollview滑动范围
101 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 103 override func viewWillAppear(_ animated: Bool) {
... ... @@ -273,26 +271,7 @@ class GrowViewController: UIViewController,UIScrollViewDelegate {
273 271 let index = CGFloat(btn.tag)
274 272  
275 273 if contentScrollView.contentSize.width>0 {
276   -
277   -// let childVC = self.childViewControllers[btn.tag]
278 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 276 if btn.tag == 0 {
298 277 self.navigationItem.rightBarButtonItem = nil
... ... @@ -301,11 +280,22 @@ class GrowViewController: UIViewController,UIScrollViewDelegate {
301 280 }
302 281 }
303 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 292 func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
305 293  
306 294 if scrollView == contentScrollView {
307 295 let offsetX = scrollView.contentOffset.x
308 296 let index = Int(offsetX/getScreenWidth())
  297 + //标记当前位置
  298 + nowIndex = index
309 299 let btn = titleBtnArr[index]
310 300 clickTitleAction(btn: btn)
311 301 }
... ...
ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/MoralViewController.swift
... ... @@ -12,7 +12,7 @@ class MoralViewController: UIViewController,UITableViewDelegate,UITableViewDataS
12 12  
13 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 16 table.backgroundColor = backGroundColor
17 17 table.delegate = self
18 18 table.dataSource = self
... ... @@ -30,8 +30,12 @@ class MoralViewController: UIViewController,UITableViewDelegate,UITableViewDataS
30 30 self.title = "德育报告"
31 31 self.view.backgroundColor = backGroundColor
32 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 39 downLoadDataFromNet()
36 40 }
37 41  
... ...
ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/ReportViewController.swift
... ... @@ -39,13 +39,24 @@ class ReportViewController: UIViewController,UITableViewDelegate,UITableViewData
39 39 self.view.addSubview(self.reportTable)
40 40 reportTable.snp.makeConstraints { (maker) in
41 41 maker.width.equalToSuperview()
42   - maker.height.equalTo(self.view.frame.size.height-60-44)
  42 + maker.bottom.equalToSuperview()
43 43 maker.top.equalTo(60)
44 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 57 override func viewDidLayoutSubviews() {
48   -
  58 + DebugLog("横屏")
  59 + DebugLog(self.view.frame.height)
49 60 }
50 61  
51 62 // MARK: - 设置日期View
... ... @@ -63,9 +74,7 @@ class ReportViewController: UIViewController,UITableViewDelegate,UITableViewData
63 74 let recognizer = UISwipeGestureRecognizer.init(target: self, action: #selector(showView))
64 75 recognizer.direction = UISwipeGestureRecognizerDirection.down
65 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 80 @objc func showView(){
... ...
ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/SceneDetailViewController.swift
... ... @@ -11,7 +11,7 @@ import UIKit
11 11 class SceneDetailViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
12 12  
13 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 15 table.backgroundColor = backGroundColor
16 16 table.delegate = self
17 17 table.dataSource = self
... ... @@ -28,7 +28,12 @@ class SceneDetailViewController: UIViewController,UITableViewDataSource,UITableV
28 28 self.title = "场景详情"
29 29 self.view.backgroundColor = backGroundColor
30 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 38 func numberOfSections(in tableView: UITableView) -> Int {
34 39 return 3
... ...
ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/CalendarView.swift
... ... @@ -10,6 +10,9 @@ import UIKit
10 10  
11 11 class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
12 12  
  13 + ///通知父控制器解除滑动限制
  14 + typealias CloseWindowBlock = ()->()
  15 +
13 16 var keyWindow = UIWindow()
14 17 var backBtn = UIButton()
15 18 var topBtn = UIButton()
... ... @@ -18,10 +21,23 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
18 21 var monthDay = Int()
19 22 var todayDay = Int()
20 23  
  24 + var viewWidth = CGFloat()
  25 + var viewHeight = CGFloat()
  26 +
  27 + var backBlock : CloseWindowBlock?
  28 +
  29 +
21 30 override init(frame: CGRect) {
22 31 super.init(frame: frame)
23 32 if !frame.isEmpty{
  33 + viewWidth = frame.width
  34 + viewWidth = frame.height
  35 + self.backgroundColor = UIColor.orange
24 36 self.addSubview(self.collectionView)
  37 + collectionView.snp.makeConstraints { (maker) in
  38 + maker.center.equalToSuperview()
  39 + maker.height.width.equalToSuperview()
  40 + }
25 41 firstDay = CalendarDateManager.shared.getFirstMonthDays()
26 42 monthDay = CalendarDateManager.shared.getCurrentMonthDay()
27 43 todayDay = CalendarDateManager.shared.getTodayDate()
... ... @@ -30,11 +46,15 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
30 46 override func layoutSubviews() {
31 47  
32 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 54 lazy var flowlayOut = {()-> UICollectionViewFlowLayout in
35 55 //设置layout
36 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 58 flowlayout.minimumLineSpacing = 0
39 59 flowlayout.minimumInteritemSpacing = 0
40 60 flowlayout.headerReferenceSize = CGSize.init(width: 0, height: 0)
... ... @@ -45,7 +65,7 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
45 65  
46 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 69 calendarView.delegate = self
50 70 calendarView.dataSource = self
51 71 calendarView.backgroundColor = UIColor.white
... ... @@ -59,19 +79,27 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
59 79  
60 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 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 87 back.backgroundColor = UIColor.black
68 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 91 key.addSubview(top)
72 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 103 self.isHidden = false
76 104 keyWindow = key
77 105 backBtn = back
... ... @@ -79,14 +107,14 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
79 107  
80 108 }
81 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 120 //MARK: - Delegate
... ... @@ -98,7 +126,6 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
98 126  
99 127 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "calendarCell", for: indexPath)
100 128 let lab = UILabel.init(frame: cell.bounds)
101   -
102 129 if indexPath.row < weekLab.count {
103 130 lab.text = weekLab[indexPath.row]
104 131 }else{
... ... @@ -121,6 +148,10 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
121 148  
122 149 lab.textAlignment = .center
123 150 cell.addSubview(lab)
  151 + lab.snp.makeConstraints { (maker) in
  152 + maker.center.equalToSuperview()
  153 + maker.height.width.equalToSuperview()
  154 + }
124 155 return cell
125 156  
126 157 }
... ...
ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/SceneMiddleCell.swift
... ... @@ -32,7 +32,12 @@ class SceneMiddleCell: UITableViewCell {
32 32 customLineChart.drawLine(point: arr3, color: UIColorWithRGB(R: 255, G: 213, B: 79))
33 33  
34 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 43 override func setSelected(_ selected: Bool, animated: Bool) {
... ...