CNMainView.swift
13.8 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
//
// CNMainView.swift
// metaCode
//
// Created by daojian on 2023/5/31.
//
import Foundation
import UIKit
///旋转动画时间
let KTransformAnimationTime:CGFloat = 0.75;
///正面View
class CNFrontMainView : UIView{
///点击反转事件
var tapTransformAciton:closureBlock?
override init(frame: CGRect) {
super.init(frame: frame)
self.initUI()
// let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapAction))
// self.addGestureRecognizer(tap)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
///视图总容器
lazy var frontTotolContentView : UIView = {
let frontTotolContentView = UIView.init(frame: CGRect(x: 0, y: 0, width: self.width, height: self.height ))
frontTotolContentView.backgroundColor = UIColor.white
frontTotolContentView.clipsToBounds = true
frontTotolContentView.layer.cornerRadius = 20
return frontTotolContentView
}()
///未认证-前置视图身份描述容器
lazy var frontDescContentView : UIView = {
let frontDescContentView = UIView.init(frame: CGRect(x: 0, y: 0, width: self.width, height: self.height ))
frontDescContentView.backgroundColor = UIColor.white
frontDescContentView.clipsToBounds = true
frontDescContentView.layer.cornerRadius = 20
frontDescContentView.addSubview(self.textViewBgImgView)
textViewBgImgView.snp.makeConstraints { make in
make.top.equalToSuperview()
make.left.equalToSuperview()
make.right.equalToSuperview()
make.bottom.equalToSuperview()
}
frontDescContentView.addSubview(self.addStandBtn)
addStandBtn.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.bottom.equalToSuperview().offset(-30)
make.width.equalTo(150)
make.height.equalTo(39)
}
frontDescContentView.addSubview(self.textView)
textView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(40)
make.left.equalToSuperview().offset(30)
make.right.equalToSuperview().offset(-30)
make.bottom.equalTo(addStandBtn.snp.top).offset(-30)
}
return frontDescContentView
}()
//未认证下 textview
lazy var textView: UITextView = {
let textView = UITextView.init()
textView.textColor = HexColor("#333333")
textView.font = UIFont.init(name: "PingFangSC-Medium", size: 13)
textView.textAlignment = .left
textView.contentMode = .scaleAspectFill
textView.sizeToFit()
textView.backgroundColor = HexColor("#004FE0", alpha: 0.1)
textView.clipsToBounds = true
textView.layer.cornerRadius = 14
textView.isUserInteractionEnabled = false
textView.backgroundColor = .clear
return textView
}()
///未认证-点击添加身份 按钮
lazy var addStandBtn: UIButton = {
let addStandBtn = UIButton(type: .custom)
addStandBtn.clipsToBounds = true
addStandBtn.layer.cornerRadius = 19.5
addStandBtn.backgroundColor = HexColor("#004FE0")
addStandBtn.setTitle("点击添加身份", for: .normal)
addStandBtn.setTitleColor(.white, for: .normal)
addStandBtn.titleLabel?.font = UIFont.init(name: "PingFangSC-Medium", size: 14)
addStandBtn.addTarget(self, action: #selector(addStandBtnAction), for: .touchUpInside)
return addStandBtn
}()
///已认证-前置视图卡片容器
lazy var frontCardContentView : UIView = {
let frontCardContentView = UIView.init(frame: CGRect(x: 0, y: 0, width: self.width, height: self.height ))
frontCardContentView.backgroundColor = UIColor.white
frontCardContentView.clipsToBounds = true
frontCardContentView.layer.cornerRadius = 20
frontCardContentView.addSubview(self.cardViewBgImgView)
cardViewBgImgView.snp.makeConstraints { make in
make.top.equalToSuperview()
make.left.equalToSuperview()
make.right.equalToSuperview()
make.bottom.equalToSuperview()
}
frontCardContentView.addSubview(self.iDCardView)
iDCardView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalToSuperview().offset(25)
make.width.equalTo(self.width-40)
make.height.equalTo((self.width-40) * 0.64)
}
return frontCardContentView
}()
/// 已认证-身份卡片
lazy var iDCardView:CNIDCardView = {
let iDCardView:CNIDCardView = CNIDCardView(frame: CGRect(x: 20, y: 25, width: self.width-40, height: (self.width-40) * 0.64))
return iDCardView
}()
/// 已认证-身份卡片
lazy var textViewBgImgView:UIImageView = {
let textViewBgImgView:UIImageView = UIImageView()
textViewBgImgView.clipsToBounds = true
textViewBgImgView.layer.cornerRadius = 20
return textViewBgImgView
}()
/// 已认证-卡片后的背景图
lazy var cardViewBgImgView:UIImageView = {
let cardViewBgImgView:UIImageView = UIImageView()
cardViewBgImgView.clipsToBounds = true
cardViewBgImgView.layer.cornerRadius = 20
return cardViewBgImgView
}()
//IDmodel
var _idModel : StandListModel?
var idModel : StandListModel? {
get{
_idModel
}
set{
_idModel = newValue
let auth = newValue!.auth
if(auth == true){
//已认证身份
//显示证件View
frontCardContentView.isHidden = false
iDCardView.idModel = newValue!
frontDescContentView.isHidden = true
cardViewBgImgView.kf.setImage(with: URL(string: _idModel!.cardBackgroundImg), placeholder: UIImage(named: "homepage_cardBGImg"))
}else
{//未认证身份
frontCardContentView.isHidden = true
//显示textview 添加身份
frontDescContentView.isHidden = false
textView.text = newValue!.description
addStandBtn.backgroundColor = HexColor(newValue!.backgroundColor)
textViewBgImgView.kf.setImage(with: URL(string: _idModel!.descBackgroundImg), placeholder: UIImage(named: "homepage_desc_bgImg"))
}
}
}
func initUI()
{
self.addSubview(self.frontTotolContentView)
self.frontTotolContentView.addSubview(self.frontDescContentView)
self.frontTotolContentView.addSubview(self.frontCardContentView)
self.makeConstraints()
}
func makeConstraints(){
}
// MARK: -按钮点击事件
@objc func tapAction(){
tapTransformAciton!()
}
@objc func addStandBtnAction() {
//跳转到添加身份页面
// currentViewController()?.navigationController?.pushViewController(CNLiveMineInputViewController.init(listModel: _idModel!), animated: true)
// DispatchQueue.main.asyncAfter(deadline: .now()+0.25){
if _idModel!.id == 9 {
showLoading(message: "")
CNLiveMineViewModel.requestApplyShopInfo { [weak self] result, respStatue in
if respStatue == .success {
if currentViewController()?.navigationController == nil{
print("nil")
}
currentViewController()?.navigationController?.pushViewController(CNLiveMineShopViewController.init(showType: .one, listModel: (self?.idModel)!, tempArray: []), animated: true)
}
}
}else{
if currentViewController()?.navigationController == nil{
print("nil")
}
currentViewController()?.navigationController?.pushViewController(CNLiveMineInputViewController.init(listModel: self._idModel!), animated: true)
}
// }
}
}
///反面View
class CNBackMainView : UIView{
///点击反转事件
var tapTransformAciton:closureBlock?
// MARK: - 懒加载
lazy var imageView:UIImageView = {
let tempImageView:UIImageView = UIImageView(frame: CGRect(x: 10, y: 10, width: self.width-20, height: self.height - 20))
tempImageView.image = UIImage(named: "homePage_backViewImage")
return tempImageView
}()
lazy var contentView : UIView = {
let contentView = UIView.init(frame: CGRect(x: 0, y: 0, width: self.width, height: self.height))
contentView.backgroundColor = UIColor.white
contentView.clipsToBounds = true
contentView.layer.cornerRadius = 20
return contentView
}()
lazy var bottomBackBtn : UIButton = {
let bottomBackBtn = UIButton(type: .custom)
bottomBackBtn.frame = CGRectMake(0, 0, 90, 40)
bottomBackBtn.centerX = self.contentView.width/2
bottomBackBtn.bottom = self.contentView.height - 15
bottomBackBtn.setTitle("回到首页", for: .normal)
bottomBackBtn.setTitleColor(UIColor("#333333"), for: .normal)
bottomBackBtn.setImage(UIImage(named: "homePage_backBtn_icon"), for: .normal)
bottomBackBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 8)
bottomBackBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
bottomBackBtn.addTarget(self, action: #selector(tapAction), for: .touchUpInside)
return bottomBackBtn
}()
//MARK: - 初始化
override init(frame: CGRect) {
super.init(frame: frame)
self.initUI()
let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapAction))
self.addGestureRecognizer(tap)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func initUI()
{
// self.addSubview(self.imageView)
self.addSubview(self.contentView)
self.contentView.addSubview(self.bottomBackBtn)
}
//MARK: - 事件
@objc func tapAction(){
tapTransformAciton!()
}
}
///中间主VIew
class CNMainView : UIView{
override init(frame: CGRect) {
super.init(frame: frame)
self.initUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//IDmodel
var _idModel : StandListModel?
var idModel : StandListModel? {
get{
_idModel
}
set{
self.frontView.idModel = newValue!
_idModel = newValue
}
}
///正面View
lazy var frontView:CNFrontMainView = {
let frontView = CNFrontMainView.init(frame: self.bounds)
frontView.tapTransformAciton = { [weak self] in
self?.transformToBacnkView();
}
return frontView
}()
///背面View
lazy var backView:CNBackMainView = {
let backView = CNBackMainView.init(frame: self.bounds)
backView.tapTransformAciton = { [weak self] in
self?.transformToFrontView()
}
return backView
}()
func initUI()
{
self.addSubview(self.frontView)
self.addSubview(self.backView)
self.backView.isHidden = true;
// self.layer.cornerRadius = 20;
// self.layer.shadowOpacity = 1;
// self.layer.shadowColor = UIColor("#eeeeee")?.cgColor
// self.layer.shadowOffset = CGSize(width: 10, height: 10)
// self.layer.shadowRadius = 10;
}
// MARK: -设置前置视图容器
func isHiddenMainFrontContentView(isHidden:Bool){
self.frontView.frontTotolContentView.isHidden = isHidden
}
// MARK: - 事件
///旋转到反面
func transformToBacnkView()
{
//旋转动画
UIView.animate(withDuration: KTransformAnimationTime) {
self.layer.transform = CATransform3DMakeRotation(.pi, 0, 1, 0);
}
//让背面也旋转180度
self.backView.layer.transform = CATransform3DMakeRotation(.pi, 0, 1, 0);
//在中间时刻进行正反面view的隐藏显示处理
let deadline = DispatchTime.now() - DispatchTimeInterval.milliseconds(50) + DispatchTimeInterval.milliseconds(Int (KTransformAnimationTime*1000/2))
DispatchQueue.main.asyncAfter(deadline: deadline, execute: DispatchWorkItem(block: {
UIView.animate(withDuration: 0.05) {
self.frontView.isHidden = true;
self.backView.isHidden = false;
}
}))
}
///旋转到正面
func transformToFrontView()
{
//旋转动画
UIView.animate(withDuration: KTransformAnimationTime) {
self.layer.transform = CATransform3DMakeRotation(0, 0, 1, 0);
} completion: { _ in
//背面恢复旋转
self.backView.layer.transform = CATransform3DMakeRotation(0, 0, 1, 0);
}
//在中间时刻进行正反面view的隐藏显示处理
let deadline = DispatchTime.now() - DispatchTimeInterval.milliseconds(50) + DispatchTimeInterval.milliseconds(Int (KTransformAnimationTime*1000/2))
DispatchQueue.main.asyncAfter(deadline: deadline, execute: DispatchWorkItem(block: {
UIView.animate(withDuration: 0.05) {
self.frontView.isHidden = false;
self.backView.isHidden = true;
}
}))
}
///缩放
open func scaledView(scale:CGFloat)
{
// self.frontView.imageView.transform = CGAffineTransformMakeScale(scale, scale);
}
}