From 4947c6d943c3ebbe243f28289affd172ef4dd631 Mon Sep 17 00:00:00 2001 From: Cao yang Date: Thu, 26 Apr 2018 10:06:44 +0800 Subject: [PATCH] 适配布局,优化操作体验 --- ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate | Bin 390348 -> 0 bytes ParentAssistant/ParentAssistant/Classes/controllers/Grow/GrowViewController.swift | 42 ++++++++++++++++-------------------------- ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/MoralViewController.swift | 10 +++++++--- ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/ReportViewController.swift | 19 ++++++++++++++----- ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/SceneDetailViewController.swift | 9 +++++++-- ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/CalendarView.swift | 63 +++++++++++++++++++++++++++++++++++++++++++++++---------------- ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/SceneMiddleCell.swift | 7 ++++++- 7 files changed, 97 insertions(+), 53 deletions(-) diff --git a/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate b/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate index 82c3f72..a2cf021 100644 Binary files a/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate and b/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/GrowViewController.swift b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/GrowViewController.swift index e99d0cc..4082d4d 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/GrowViewController.swift +++ b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/GrowViewController.swift @@ -51,11 +51,11 @@ class GrowViewController: UIViewController,UIScrollViewDelegate { view.addSubview(imageView) return view }() - + //导航栏左侧按钮 var titleLeftLab = UILabel() - - var childDataModel = StudentClassInfoModel() - + //当前显示的控制器 + var nowIndex = 0 + //是否显示右侧按钮 var rightBtn = UIBarButtonItem() @@ -94,12 +94,10 @@ class GrowViewController: UIViewController,UIScrollViewDelegate { maker.centerX.equalTo((CGFloat(i)+0.5)*width) maker.centerY.equalTo(contentScrollView) } - - print("childView Frame=\(vc.view.frame)") } //设置scrollview滑动范围 contentScrollView.contentSize = CGSize.init(width: width*CGFloat(titleArr.count), height: 0) -// contentScrollView.setContentOffset(CGPoint.init(x: 0, y: 0), animated: true) + contentScrollView.setContentOffset(CGPoint.init(x: CGFloat(nowIndex)*width, y: 0), animated: true) } override func viewWillAppear(_ animated: Bool) { @@ -273,26 +271,7 @@ class GrowViewController: UIViewController,UIScrollViewDelegate { let index = CGFloat(btn.tag) if contentScrollView.contentSize.width>0 { - -// let childVC = self.childViewControllers[btn.tag] contentScrollView.setContentOffset(CGPoint.init(x: index*contentScrollView.bounds.size.width, y: 0), animated: true) - -// if self.contentScrollView.subviews.contains(childVC.view){ -// //已有view,直接移动 -// //移动scrollview -// viewDidLayoutSubviews() -// contentScrollView.setContentOffset(CGPoint.init(x: index*contentScrollView.bounds.size.width, y: 0), animated: true) -// }else{ -// //新加view,刷新数据 -// self.contentScrollView.addSubview(childVC.view) -// childVC.view.snp.makeConstraints { (maker) in -// maker.width.height.equalTo(self.contentScrollView) -// maker.centerX.equalTo((index+0.5)*contentScrollView.bounds.size.width) -// maker.centerY.equalTo(self.contentScrollView) -// } -// //移动scrollview -// contentScrollView.setContentOffset(CGPoint.init(x: index*screenWidth, y: 0), animated: true) -// } } if btn.tag == 0 { self.navigationItem.rightBarButtonItem = nil @@ -301,11 +280,22 @@ class GrowViewController: UIViewController,UIScrollViewDelegate { } } //MARK: - ScrollView Delegate + func scrollViewDidScroll(_ scrollView: UIScrollView) { + let vc = self.childViewControllers[1] as! ReportViewController + scrollView.isScrollEnabled = vc.calendar.isHidden + vc.calendar.backBlock = { + DebugLog("日期消失,解除滑动锁定!") + scrollView.isScrollEnabled = true + } + } + func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { if scrollView == contentScrollView { let offsetX = scrollView.contentOffset.x let index = Int(offsetX/getScreenWidth()) + //标记当前位置 + nowIndex = index let btn = titleBtnArr[index] clickTitleAction(btn: btn) } diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/MoralViewController.swift b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/MoralViewController.swift index 8813076..6059790 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/MoralViewController.swift +++ b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/MoralViewController.swift @@ -12,7 +12,7 @@ class MoralViewController: UIViewController,UITableViewDelegate,UITableViewDataS lazy var tableView = {()->UITableView in - let table = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: screenWidth, height: screenHeight-navigationBarHeight!-statusBarHeight-10)) + let table = UITableView.init(frame: self.view.bounds) table.backgroundColor = backGroundColor table.delegate = self table.dataSource = self @@ -30,8 +30,12 @@ class MoralViewController: UIViewController,UITableViewDelegate,UITableViewDataS self.title = "德育报告" self.view.backgroundColor = backGroundColor self.view.addSubview(self.tableView) - - + tableView.snp.makeConstraints { (maker) in + maker.width.equalToSuperview() + maker.bottom.equalToSuperview() + maker.top.equalToSuperview() + maker.centerX.equalToSuperview() + } downLoadDataFromNet() } diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/ReportViewController.swift b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/ReportViewController.swift index e68ffc4..d5e30e6 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/ReportViewController.swift +++ b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/ReportViewController.swift @@ -39,13 +39,24 @@ class ReportViewController: UIViewController,UITableViewDelegate,UITableViewData self.view.addSubview(self.reportTable) reportTable.snp.makeConstraints { (maker) in maker.width.equalToSuperview() - maker.height.equalTo(self.view.frame.size.height-60-44) + maker.bottom.equalToSuperview() maker.top.equalTo(60) maker.centerX.equalToSuperview() } + + calendar = CalendarView.init(frame: CGRect.init(x: 0, y: 0, width: screenWidth, height: 245)) + self.view.addSubview(calendar) + calendar.snp.makeConstraints { (maker) in + maker.width.equalToSuperview() + maker.height.equalTo(245) + maker.centerX.equalToSuperview() + maker.top.equalTo(headView) + } + calendar.isHidden = true } override func viewDidLayoutSubviews() { - + DebugLog("横屏") + DebugLog(self.view.frame.height) } // MARK: - 设置日期View @@ -63,9 +74,7 @@ class ReportViewController: UIViewController,UITableViewDelegate,UITableViewData let recognizer = UISwipeGestureRecognizer.init(target: self, action: #selector(showView)) recognizer.direction = UISwipeGestureRecognizerDirection.down headView.addGestureRecognizer(recognizer) - - calendar = CalendarView.init(frame: CGRect.init(x: 0, y: y*2, width: screenWidth, height: 245)) - + } @objc func showView(){ diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/SceneDetailViewController.swift b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/SceneDetailViewController.swift index a315cca..14b132f 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/SceneDetailViewController.swift +++ b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Report/SceneDetailViewController.swift @@ -11,7 +11,7 @@ import UIKit class SceneDetailViewController: UIViewController,UITableViewDataSource,UITableViewDelegate { lazy var sceneTableView = {()->UITableView in - let table = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: screenWidth, height: screenHeight-navigationBarHeight!-statusBarHeight-10)) + let table = UITableView.init(frame: self.view.bounds) table.backgroundColor = backGroundColor table.delegate = self table.dataSource = self @@ -28,7 +28,12 @@ class SceneDetailViewController: UIViewController,UITableViewDataSource,UITableV self.title = "场景详情" self.view.backgroundColor = backGroundColor self.view.addSubview(self.sceneTableView) - + sceneTableView.snp.makeConstraints { (maker) in + maker.width.equalToSuperview() + maker.bottom.equalToSuperview() + maker.top.equalToSuperview() + maker.centerX.equalToSuperview() + } } func numberOfSections(in tableView: UITableView) -> Int { return 3 diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/CalendarView.swift b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/CalendarView.swift index a1c4fa1..bd69003 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/CalendarView.swift +++ b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/CalendarView.swift @@ -10,6 +10,9 @@ import UIKit class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { + ///通知父控制器解除滑动限制 + typealias CloseWindowBlock = ()->() + var keyWindow = UIWindow() var backBtn = UIButton() var topBtn = UIButton() @@ -18,10 +21,23 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { var monthDay = Int() var todayDay = Int() + var viewWidth = CGFloat() + var viewHeight = CGFloat() + + var backBlock : CloseWindowBlock? + + override init(frame: CGRect) { super.init(frame: frame) if !frame.isEmpty{ + viewWidth = frame.width + viewWidth = frame.height + self.backgroundColor = UIColor.orange self.addSubview(self.collectionView) + collectionView.snp.makeConstraints { (maker) in + maker.center.equalToSuperview() + maker.height.width.equalToSuperview() + } firstDay = CalendarDateManager.shared.getFirstMonthDays() monthDay = CalendarDateManager.shared.getCurrentMonthDay() todayDay = CalendarDateManager.shared.getTodayDate() @@ -30,11 +46,15 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { override func layoutSubviews() { self.flowlayOut.itemSize = CGSize.init(width: self.bounds.size.width/7, height: 35) + viewWidth = self.bounds.size.width + viewHeight = self.bounds.size.height + } + lazy var flowlayOut = {()-> UICollectionViewFlowLayout in //设置layout let flowlayout = UICollectionViewFlowLayout() - flowlayout.itemSize = CGSize.init(width: self.bounds.size.width/7, height:35) + flowlayout.itemSize = CGSize.init(width: viewWidth/7, height:35) flowlayout.minimumLineSpacing = 0 flowlayout.minimumInteritemSpacing = 0 flowlayout.headerReferenceSize = CGSize.init(width: 0, height: 0) @@ -45,7 +65,7 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { lazy var collectionView = {()-> UICollectionView in - let calendarView = UICollectionView.init(frame: self.bounds, collectionViewLayout: flowlayOut) + let calendarView = UICollectionView.init(frame: self.bounds, collectionViewLayout: self.flowlayOut) calendarView.delegate = self calendarView.dataSource = self calendarView.backgroundColor = UIColor.white @@ -59,19 +79,27 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { let key = UIApplication.shared.keyWindow! - let top = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: self.bounds.size.width, height: self.frame.origin.y)) + let top = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: viewWidth, height: statusBarHeight+navigationBarHeight!)) top.backgroundColor = UIColor.clear - top.addTarget(self, action: #selector(closeView(btn:)), for: UIControlEvents.allEvents) + top.addTarget(self, action: #selector(closeView), for: UIControlEvents.allEvents) - let back = UIButton.init(frame: CGRect.init(x: 0, y: self.bounds.size.height, width: screenWidth, height: screenHeight)) + let back = UIButton.init(frame: CGRect.init(x: 0, y: viewHeight+statusBarHeight+navigationBarHeight!, width: viewWidth, height: screenHeight*2)) back.backgroundColor = UIColor.black back.alpha = 0.4 - back.addTarget(self, action: #selector(closeView(btn:)), for: UIControlEvents.allEvents) + back.addTarget(self, action: #selector(closeView), for: UIControlEvents.allEvents) key.addSubview(top) key.addSubview(back) - key.addSubview(self) - + top.snp.makeConstraints { (maker) in + maker.width.equalToSuperview() + maker.height.equalTo(statusBarHeight+navigationBarHeight!) + maker.top.equalToSuperview() + } + back.snp.makeConstraints { (maker) in + maker.width.equalToSuperview() + maker.height.equalToSuperview() + maker.top.equalTo(viewHeight+statusBarHeight+navigationBarHeight!) + } self.isHidden = false keyWindow = key backBtn = back @@ -79,14 +107,14 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { } //MARK: - 关闭视图 - @objc func closeView(btn:UIButton) { + @objc private func closeView() { + + self.backBlock!() + self.backBtn.removeFromSuperview() + self.topBtn.removeFromSuperview() + self.keyWindow = UIWindow.init() + self.isHidden = true - UIView.animate(withDuration: 0.3) { - self.backBtn.removeFromSuperview() - self.topBtn.removeFromSuperview() - self.keyWindow = UIWindow.init() - self.isHidden = true - } } //MARK: - Delegate @@ -98,7 +126,6 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "calendarCell", for: indexPath) let lab = UILabel.init(frame: cell.bounds) - if indexPath.row < weekLab.count { lab.text = weekLab[indexPath.row] }else{ @@ -121,6 +148,10 @@ class CalendarView: UIView,UICollectionViewDelegate,UICollectionViewDataSource { lab.textAlignment = .center cell.addSubview(lab) + lab.snp.makeConstraints { (maker) in + maker.center.equalToSuperview() + maker.height.width.equalToSuperview() + } return cell } diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/SceneMiddleCell.swift b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/SceneMiddleCell.swift index 2beaba1..a1052d1 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/SceneMiddleCell.swift +++ b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/View/ReportView/SceneMiddleCell.swift @@ -32,7 +32,12 @@ class SceneMiddleCell: UITableViewCell { customLineChart.drawLine(point: arr3, color: UIColorWithRGB(R: 255, G: 213, B: 79)) self.addSubview(customLineChart) - + customLineChart.snp.makeConstraints { (maker) in + maker.top.equalTo(60) + maker.left.equalTo(20) + maker.right.equalTo(20) + maker.bottom.equalToSuperview() + } } override func setSelected(_ selected: Bool, animated: Bool) { -- libgit2 0.21.0