Commit aac8a0db6a616a7e52eea9436e855d81ccf7910a
1 parent
ce92fb65
首页添加引导图
Showing
4 changed files
with
216 additions
and
7 deletions
Podfile
metaCode/Classes/Main/HomePage/Controller/CNMetaCodeHomePageController.swift
| ... | ... | @@ -8,12 +8,65 @@ |
| 8 | 8 | import Foundation |
| 9 | 9 | import UIKit |
| 10 | 10 | import YYCategories |
| 11 | +import SwiftGifOrigin | |
| 11 | 12 | |
| 12 | 13 | let Width: CGFloat = UIScreen.main.bounds.size.width |
| 13 | 14 | let Height: CGFloat = UIScreen.main.bounds.size.height |
| 14 | 15 | |
| 16 | +///存储是否第一次显示首页上滑引导 | |
| 17 | +let CNKeyIsFirstAppearUpSlideHomeGuide: String = "isFirstAppearUpSlideHomeGuideKey" | |
| 18 | +///存储是否第一次显示首页下滑引导 | |
| 19 | +let CNKeyIsFirstAppearDownSlideHomeGuide: String = "isFirstAppearDownSlideHomeGuideKey" | |
| 20 | + | |
| 15 | 21 | class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDelegate, NewPagedFlowViewDataSource, CNCustomIndexViewDelegate{ |
| 16 | 22 | |
| 23 | + ///上滑引导View | |
| 24 | + lazy var upSlideGuideView:CNHomePageGuideView = { | |
| 25 | + let upSlideGuideView = CNHomePageGuideView.init(frame: UIScreen.main.bounds) | |
| 26 | + upSlideGuideView.setBottomText(text: "向上滑动") | |
| 27 | + upSlideGuideView.skipAction = { | |
| 28 | + [weak self] in | |
| 29 | + self?.upSlideGuideView.removeFromSuperview() | |
| 30 | + self?.upSlideGifView.removeFromSuperview() | |
| 31 | + UserDefaults.standard.set("flase", forKey: CNKeyIsFirstAppearUpSlideHomeGuide) | |
| 32 | + UserDefaults.standard.set("flase", forKey: CNKeyIsFirstAppearDownSlideHomeGuide) | |
| 33 | + self?.pageFlowView.scrollView.isScrollEnabled = true | |
| 34 | + } | |
| 35 | + return upSlideGuideView | |
| 36 | + }() | |
| 37 | + ///上滑引导动图 | |
| 38 | + lazy var upSlideGifView:UIImageView = { | |
| 39 | + let gif: UIImageView = UIImageView(frame: CGRect(x: 200, y: 30, width: 40, height: 80)) | |
| 40 | + gif.loadGif(name: "slide_up") | |
| 41 | + gif.center = self.view.center | |
| 42 | + gif.contentMode = .scaleAspectFill | |
| 43 | + | |
| 44 | + return gif | |
| 45 | + }() | |
| 46 | + | |
| 47 | + ///下滑引导View | |
| 48 | + lazy var downSlideGuideView:CNHomePageGuideView = { | |
| 49 | + let downSlideGuideView = CNHomePageGuideView.init(frame: UIScreen.main.bounds) | |
| 50 | + downSlideGuideView.setBottomText(text: "向下滑动") | |
| 51 | + downSlideGuideView.skipAction = { | |
| 52 | + [weak self ] in | |
| 53 | + self?.downSlideGuideView.removeFromSuperview() | |
| 54 | + self?.downSlideGifView.removeFromSuperview() | |
| 55 | + UserDefaults.standard.set("flase", forKey: CNKeyIsFirstAppearDownSlideHomeGuide) | |
| 56 | + self?.pageFlowView.scrollView.isScrollEnabled = true | |
| 57 | + } | |
| 58 | + return downSlideGuideView | |
| 59 | + }() | |
| 60 | + ///下滑引导动图 | |
| 61 | + lazy var downSlideGifView:UIImageView = { | |
| 62 | + let gif: UIImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 40, height: 80)) | |
| 63 | + gif.center = self.view.center | |
| 64 | + gif.loadGif(name: "slide_down") | |
| 65 | + gif.contentMode = .scaleAspectFill | |
| 66 | + return gif | |
| 67 | + }() | |
| 68 | + | |
| 69 | + | |
| 17 | 70 | ///NewPagedFlowView 开始滑动时的偏移量 |
| 18 | 71 | private var beginOffset = 0.0 |
| 19 | 72 | |
| ... | ... | @@ -66,6 +119,7 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel |
| 66 | 119 | |
| 67 | 120 | // self.tabBarController?.tabBar.top = self.tabBarY + KSreenHeight |
| 68 | 121 | |
| 122 | + | |
| 69 | 123 | } |
| 70 | 124 | override func viewWillAppear(_ animated: Bool) { |
| 71 | 125 | super.viewWillAppear(animated) |
| ... | ... | @@ -75,7 +129,28 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel |
| 75 | 129 | self.view.height = KSreenHeight |
| 76 | 130 | |
| 77 | 131 | self.topNavView.isHidden = true |
| 132 | + | |
| 78 | 133 | |
| 134 | +// | |
| 135 | +// | |
| 136 | +// let maskView = UIView.init(frame: UIScreen.main.bounds) | |
| 137 | +// maskView.backgroundColor = .black.withAlphaComponent(0.7) | |
| 138 | +// maskView.isUserInteractionEnabled = false | |
| 139 | +// | |
| 140 | +// let path:UIBezierPath = UIBezierPath.init(rect: UIScreen.main.bounds) | |
| 141 | +// | |
| 142 | +// let W = KSreenWidth-50 | |
| 143 | +// let H = W*1.5 | |
| 144 | +// let rect = CGRectMake(25, (KSreenHeight-H)/2,W, H) | |
| 145 | +// | |
| 146 | +// let appendPath: UIBezierPath = UIBezierPath.init(roundedRect: rect, cornerRadius: 20) | |
| 147 | +// path.append(appendPath.reversing()) | |
| 148 | +// let shapeLayer: CAShapeLayer = CAShapeLayer() | |
| 149 | +// shapeLayer.path = path.cgPath; | |
| 150 | +// maskView.layer.mask = shapeLayer; | |
| 151 | +// | |
| 152 | +// self.view.addSubview(maskView) | |
| 153 | + | |
| 79 | 154 | } |
| 80 | 155 | // MARK: - 添加UI |
| 81 | 156 | func setupUI(){ |
| ... | ... | @@ -84,6 +159,30 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel |
| 84 | 159 | self.view.addSubview(self.pageFlowView) |
| 85 | 160 | self.pageFlowView.reloadData() |
| 86 | 161 | |
| 162 | + //首选判断是否显示了上滑引导 | |
| 163 | + let isFirstAppearUpSlideHomeGuide:Any? = UserDefaults.standard.object(forKey: CNKeyIsFirstAppearUpSlideHomeGuide) | |
| 164 | + | |
| 165 | + if let tempGuide = isFirstAppearUpSlideHomeGuide{ | |
| 166 | + //已经显示过上滑引导 | |
| 167 | + | |
| 168 | + //判断是否显示过下滑引导 | |
| 169 | + let isFirstAppearDownSlideHomeGuide:Any? = UserDefaults.standard.object(forKey: CNKeyIsFirstAppearDownSlideHomeGuide) | |
| 170 | + if let tempDownGuide = isFirstAppearDownSlideHomeGuide{ | |
| 171 | + | |
| 172 | + }else{ | |
| 173 | + //没有显示下滑引导 | |
| 174 | + self.pageFlowView.scrollView.isScrollEnabled = false | |
| 175 | + self.view.addSubview(self.downSlideGuideView) | |
| 176 | + self.view.addSubview(self.downSlideGifView) | |
| 177 | + } | |
| 178 | + | |
| 179 | + }else{ | |
| 180 | + //没显示过上滑引导 | |
| 181 | + self.pageFlowView.scrollView.isScrollEnabled = false | |
| 182 | + self.view.addSubview(self.upSlideGuideView) | |
| 183 | + self.view.addSubview(self.upSlideGifView) | |
| 184 | + } | |
| 185 | + | |
| 87 | 186 | } |
| 88 | 187 | |
| 89 | 188 | // MARK: - NewPagedFlowView代理 |
| ... | ... | @@ -169,7 +268,6 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel |
| 169 | 268 | |
| 170 | 269 | self.backgroupView.replaceCurerrentApearView(fromIndex: self.backgroupView.currentApearViewIndex, toIndex: toIndex) |
| 171 | 270 | |
| 172 | - | |
| 173 | 271 | } |
| 174 | 272 | |
| 175 | 273 | |
| ... | ... | @@ -177,6 +275,25 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel |
| 177 | 275 | |
| 178 | 276 | func customIndexViewWillBeiginScroll(scrollView: UIScrollView) { |
| 179 | 277 | self.view.height = KSreenHeight |
| 278 | + | |
| 279 | + /**开始拖拽移除引导View**/ | |
| 280 | + | |
| 281 | + //移除上滑引导 | |
| 282 | + if(self.upSlideGuideView.superview != nil){ | |
| 283 | + self.upSlideGuideView.removeFromSuperview() | |
| 284 | + self.upSlideGifView.removeFromSuperview() | |
| 285 | + UserDefaults.standard.set("flase", forKey: CNKeyIsFirstAppearUpSlideHomeGuide) | |
| 286 | + } | |
| 287 | + | |
| 288 | + //移除下滑引导 | |
| 289 | + if (self.downSlideGuideView.superview != nil) { | |
| 290 | + self.downSlideGuideView.removeFromSuperview() | |
| 291 | + self.downSlideGifView.removeFromSuperview() | |
| 292 | + UserDefaults.standard.set("flase", forKey: CNKeyIsFirstAppearDownSlideHomeGuide) | |
| 293 | + self.pageFlowView.scrollView.isScrollEnabled = true | |
| 294 | + } | |
| 295 | + | |
| 296 | + | |
| 180 | 297 | } |
| 181 | 298 | func customIndexViewDidScroll(scrollView: UIScrollView) { |
| 182 | 299 | //让tabbar跟随scrollView平移量进行移动 |
| ... | ... | @@ -191,6 +308,17 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel |
| 191 | 308 | func customIndexViewDidEndScroll(scrollView: UIScrollView) { |
| 192 | 309 | if scrollView.contentOffset.y == KSreenHeight { |
| 193 | 310 | self.view.height = self.tabBarY |
| 311 | + | |
| 312 | + //判断是否显示过下滑引导 | |
| 313 | + let isFirstAppearDownSlideHomeGuide:Any? = UserDefaults.standard.object(forKey: CNKeyIsFirstAppearDownSlideHomeGuide) | |
| 314 | + if let tempDownGuide = isFirstAppearDownSlideHomeGuide{ | |
| 315 | + print("不该进来") | |
| 316 | + }else{ | |
| 317 | + //没有显示下滑引导 | |
| 318 | + self.view.addSubview(self.downSlideGuideView) | |
| 319 | + self.view.addSubview(self.downSlideGifView) | |
| 320 | + self.pageFlowView.scrollView.isScrollEnabled = false | |
| 321 | + } | |
| 194 | 322 | } |
| 195 | 323 | } |
| 196 | 324 | ... | ... |
metaCode/Classes/Main/HomePage/View/CNCustomIndexView.swift
| ... | ... | @@ -131,8 +131,8 @@ class CNCustomIndexView:PGIndexBannerSubiew, UIScrollViewDelegate, WJColorChange |
| 131 | 131 | ///中间主界面 |
| 132 | 132 | lazy var mainView:CNMainView = { |
| 133 | 133 | let W = self.width |
| 134 | - let H = W*1.5 | |
| 135 | - let mainView = CNMainView.init(frame: CGRectMake(0, self.frame.size.height + (self.frame.size.height-H)/2,W, H)) | |
| 134 | + let H = W*1.5 | |
| 135 | + let mainView = CNMainView.init(frame: CGRectMake(0, self.frame.size.height + KSreenHeight*0.16,W, H)) | |
| 136 | 136 | return mainView |
| 137 | 137 | }() |
| 138 | 138 | |
| ... | ... | @@ -141,6 +141,7 @@ class CNCustomIndexView:PGIndexBannerSubiew, UIScrollViewDelegate, WJColorChange |
| 141 | 141 | let collectionView = CNCollectMoneyCodeView.init(frame: CGRectMake(-25, 0, self.frame.size.width + 50, self.frame.size.height)) |
| 142 | 142 | collectionView.backAction = {[weak self] in |
| 143 | 143 | self?.baseScrollView.setContentOffset(CGPoint(x: 0, y: (self!.baseScrollView.height)), animated: true) |
| 144 | + self?.superScrollView?.isScrollEnabled = true | |
| 144 | 145 | } |
| 145 | 146 | return collectionView |
| 146 | 147 | }() |
| ... | ... | @@ -357,16 +358,15 @@ class CNCustomIndexView:PGIndexBannerSubiew, UIScrollViewDelegate, WJColorChange |
| 357 | 358 | self.collectMoneyCodeView.contentView.backgroundColor = KVCBackgroupColor |
| 358 | 359 | } |
| 359 | 360 | |
| 360 | - //外部代理 | |
| 361 | - self.delegate?.customIndexViewDidEndScroll(scrollView: scrollView) | |
| 362 | - | |
| 363 | - | |
| 364 | 361 | |
| 365 | 362 | //滑动结束 把topNavView 放到scrollView的上层 |
| 366 | 363 | self.bringSubviewToFront(self.topNavView) |
| 367 | 364 | |
| 368 | 365 | //下滑提醒View回到初始位置 |
| 369 | 366 | self.topCollectMoneyRemindView.top = -(self.topCollectMoneyRemindView.height + 50) |
| 367 | + | |
| 368 | + //外部代理 | |
| 369 | + self.delegate?.customIndexViewDidEndScroll(scrollView: scrollView) | |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | } | ... | ... |
metaCode/Classes/Main/HomePage/View/CNHomePageGuideView.swift
| ... | ... | @@ -7,6 +7,85 @@ |
| 7 | 7 | |
| 8 | 8 | import Foundation |
| 9 | 9 | |
| 10 | +typealias skipGuideBlock = ()->Void | |
| 11 | + | |
| 10 | 12 | class CNHomePageGuideView: UIView{ |
| 13 | + ///跳过引导事件回调 | |
| 14 | + var skipAction: skipGuideBlock? | |
| 15 | + | |
| 16 | + lazy var skipButtom: UIButton = { | |
| 17 | + | |
| 18 | + let skipButtom = UIButton(type: .custom) | |
| 19 | + skipButtom.frame = CGRect(x: 0, y: 0, width: 90, height: 30) | |
| 20 | + skipButtom.right = self.width - 30 | |
| 21 | + skipButtom.top = KStatusBarHeight + 30 | |
| 22 | + skipButtom.setTitle("跳过引导", for: .normal) | |
| 23 | + skipButtom.setTitleColor(.white, for: .normal) | |
| 24 | + skipButtom.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .medium) | |
| 25 | + skipButtom.clipsToBounds = true | |
| 26 | + skipButtom.layer.cornerRadius = skipButtom.height/2 | |
| 27 | + skipButtom.layer.borderColor = UIColor("#979797")?.cgColor | |
| 28 | + skipButtom.layer.borderWidth = 0.5 | |
| 29 | + | |
| 30 | + return skipButtom | |
| 31 | + | |
| 32 | + }() | |
| 33 | + | |
| 34 | + lazy var bottomLabel: UILabel = { | |
| 35 | + let bottomLabel = UILabel.init(frame: CGRect(x: 0, y: 0, width: 150, height: 20)) | |
| 36 | + bottomLabel.textColor = .white | |
| 37 | + bottomLabel.font = UIFont.systemFont(ofSize: 18, weight: .medium) | |
| 38 | + bottomLabel.textAlignment = .center | |
| 39 | + return bottomLabel | |
| 40 | + }() | |
| 41 | + | |
| 42 | + override init(frame: CGRect) { | |
| 43 | + super.init(frame: frame) | |
| 44 | + self.initUI() | |
| 45 | + } | |
| 46 | + | |
| 47 | + required init?(coder: NSCoder) { | |
| 48 | + fatalError("init(coder:) has not been implemented") | |
| 49 | + } | |
| 50 | + func initUI(){ | |
| 51 | + | |
| 52 | + self.addSubview(self.skipButtom) | |
| 53 | + | |
| 54 | + self.backgroundColor = .black.withAlphaComponent(0.7) | |
| 55 | + self.isUserInteractionEnabled = false | |
| 56 | + | |
| 57 | + //通过设置mask透明区域来实现镂空效果 | |
| 58 | + let path:UIBezierPath = UIBezierPath.init(rect: UIScreen.main.bounds) | |
| 59 | + | |
| 60 | + //rect 首页被镂空的区域 | |
| 61 | + let W = KSreenWidth-50 | |
| 62 | + let H = W*1.5 | |
| 63 | + let rect = CGRectMake(25, KSreenHeight*0.16,W, H) | |
| 64 | + | |
| 65 | + let appendPath: UIBezierPath = UIBezierPath.init(roundedRect: rect, cornerRadius: 20) | |
| 66 | + path.append(appendPath.reversing()) | |
| 67 | + | |
| 68 | + let shapeLayer: CAShapeLayer = CAShapeLayer() | |
| 69 | + shapeLayer.path = path.cgPath; | |
| 70 | + self.layer.mask = shapeLayer | |
| 71 | + | |
| 72 | + //更新bottomLabel位置 | |
| 73 | + self.bottomLabel.centerX = self.centerX | |
| 74 | + self.bottomLabel.top = CGRectGetMaxY(rect) + 20 | |
| 75 | + self.addSubview(self.bottomLabel) | |
| 76 | + } | |
| 77 | + | |
| 78 | + override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { | |
| 79 | + | |
| 80 | + if((self.skipButtom.layer.hitTest(point)) != nil){ | |
| 81 | +// print("点击了跳过") | |
| 82 | + self.skipAction!() | |
| 83 | + } | |
| 84 | + //让事件响应链进行执行 | |
| 85 | + return super.hitTest(point, with: event) | |
| 86 | + } | |
| 11 | 87 | |
| 88 | + func setBottomText(text: String)->Void{ | |
| 89 | + self.bottomLabel.text = text | |
| 90 | + } | |
| 12 | 91 | } | ... | ... |