CNDownSlideView.swift
6.46 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//
// CNDownSlideView.swift
// metaCode
//
// Created by daojian on 2023/5/30.
// 下滑后的上面页面
import Foundation
import UIKit
import WebKit
typealias backBlock = ()->Void;
///下滑显示的View
class CNDownSlideView:UIView{
//返回首页
var backAction:backBlock?
//MARK: - 懒加载
lazy var contentView:UIView = {
let contentView = UIView.init(frame: CGRect(x: 0, y: 0, width: self.width, height: self.height))
contentView.backgroundColor = UIColor.clear
contentView.isUserInteractionEnabled = true
// let path:UIBezierPath = UIBezierPath.init(roundedRect: contentView.bounds, byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize.init(width: 20, height: 20))
//
// let maskLayer:CAShapeLayer = CAShapeLayer()
// maskLayer.frame = contentView.bounds
// maskLayer.path = path.cgPath
// contentView.layer.mask = maskLayer
// let imageView = UIImageView(frame: CGRect(x: 10, y: 20, width: contentView.width - 20, height: contentView.height - 40))
// imageView.image = UIImage(named: "homePage_collectMoneyImage")
// contentView.addSubview(imageView)
return contentView
}()
//h5网页
// TODO: H:-10原为self.height-KTabBarHeight,但有白条,改成了-10
lazy var webView: WKWebView = {
let webView = WKWebView.init(frame: CGRectMake(0, 0, self.width, self.height-KTabBarHeight-10))
webView.scrollView.showsVerticalScrollIndicator = false
webView.scrollView.showsHorizontalScrollIndicator = false
webView.backgroundColor = .clear
webView.isOpaque = false
return webView
}()
lazy var upSlideVC:CNUpSlideViewController = {
let upSlideVC = CNUpSlideViewController.init()
upSlideVC.view.width = KSreenWidth
upSlideVC.view.height = KSreenHeight-DownSlideBottomViewHeight
return upSlideVC
}()
lazy var shopConsoleVC:CNLiveShopConsoleController = {
let shopConsoleVC = CNLiveShopConsoleController.init()
shopConsoleVC.view.width = KSreenWidth
shopConsoleVC.view.height = KSreenHeight-DownSlideBottomViewHeight
return shopConsoleVC
}()
var type:Int?
var _downPath:String?
var downPath:String? {
get{
return _downPath
}
set{
_downPath = newValue!
if(type == UpDownTypeH5){
self.contentView.addSubview(self.webView)
if (_downPath != ""){
let webUrl: URL! = URL.init(string: _downPath!)
webView.load(URLRequest.init(url:webUrl))
}
}else if(type == UpDownTypePage){
self.addSubview(self.upSlideVC.view)
self.upSlideVC.downPath = _downPath
}else if(type == UpDownTypeShopDetail){
}else if(type == UpDownTypeShopControlConsole){
var isContainVC = false
currentViewController()?.children.forEach({ vc in
if vc == self.shopConsoleVC{
isContainVC = true
}
})
if isContainVC == false{
currentViewController()?.addChild(self.shopConsoleVC)
self.shopConsoleVC.didMove(toParent: currentViewController())
}
self.addSubview(self.shopConsoleVC.view)
}
}
}
lazy var bottomView:UIView = {
let bottomView = UIView(frame: CGRect(x:0, y:self.height - DownSlideBottomViewHeight, width: self.width, height: DownSlideBottomViewHeight))
bottomView.backgroundColor = HexColor("#FFFFFF")
bottomView.isHidden = true
// let path:UIBezierPath = UIBezierPath.init(roundedRect: bottomView.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize.init(width: 50, height: 50))
// let maskLayer:CAShapeLayer = CAShapeLayer()
// maskLayer.frame = bottomView.bounds
// maskLayer.path = path.cgPath
// bottomView.layer.mask = maskLayer
// bottomView.clipsToBounds = true
// bottomView.layer.cornerRadius = 50
// bottomView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
// 设置阴影效果
bottomView.layer.masksToBounds = false
//定义view的阴影颜色
bottomView.layer.shadowColor = UIColor(red: 0.55, green: 0.68, blue: 0.86, alpha: 0.1).cgColor
//定义view的阴影透明度,注意:如果view没有设置背景色阴影也是不会显示的
bottomView.layer.shadowOpacity = 1
//定义view的阴影宽度,模糊计算的半径
bottomView.layer.shadowRadius = 15.0
//阴影偏移量
bottomView.layer.shadowOffset = CGSize(width: 0, height: -3)
bottomView.layer.cornerRadius = 50
bottomView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
let backBtn: UIButton = UIButton(type: .custom)
backBtn.frame = CGRectMake(0, 0, 100, DownSlideBottomViewHeight)
backBtn.centerX = bottomView.width/2
backBtn.centerY = bottomView.height/2
backBtn.setImage(UIImage(named: "homePage_backhome_icon"), for: .normal)
backBtn.setTitle("回到首页", for: .normal)
backBtn.setTitleColor(UIColor("#2076FF"), for: .normal)
backBtn.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: .medium)
backBtn.addTarget(self, action: #selector(backBtnAction), for: .touchUpInside)
backBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 8)
bottomView.addSubview(backBtn)
return bottomView
}()
override init(frame: CGRect) {
super.init(frame: frame)
let tap = UITapGestureRecognizer.init(target: self, action: #selector(slideViewTap))
tap.cancelsTouchesInView = false
self.addGestureRecognizer(tap)
self.initUI()
}
@objc func slideViewTap() {
print("slideViewTap")
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
///初始化UI
func initUI(){
self.isUserInteractionEnabled = true
self.addSubview(self.contentView)
self.addSubview(self.bottomView)
}
@objc func backBtnAction(){
self.backAction!()
}
}