CNMainView.swift
17.9 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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
//
// CNMainView.swift
// metaCode
//
// Created by daojian on 2023/5/31.
// 认证--中间屏主视图
import Foundation
import UIKit
import Kingfisher
///旋转动画时间
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.upMoreGIF)
upMoreGIF.snp.makeConstraints { make in
make.top.equalToSuperview().offset(5)
make.right.equalToSuperview().offset(-self.width/2+24)
make.width.equalTo(48)
make.height.equalTo(30)
}
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.personalStandBtn)
personalStandBtn.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-self.width/2)
make.bottom.equalToSuperview().offset(-45)
make.width.equalTo(120)
make.height.equalTo(36)
}
frontDescContentView.addSubview(self.enterpriseStandBtn)
enterpriseStandBtn.snp.makeConstraints { make in
make.left.equalTo(self.personalStandBtn.snp.right)
make.bottom.equalToSuperview().offset(-45)
make.width.equalTo(120)
make.height.equalTo(36)
}
frontDescContentView.addSubview(self.downMoreGIF)
downMoreGIF.snp.makeConstraints { make in
make.top.equalTo(self.personalStandBtn.snp.bottom).offset((45-30)/2.0)
make.centerX.equalTo(self.personalStandBtn.snp.right)
make.width.equalTo(96)
make.height.equalTo(30)
}
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(enterpriseStandBtn.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 personalStandBtn: UIButton = {
let personalStandBtn = UIButton(type: .custom)
personalStandBtn.layer.cornerRadius = 19.5
personalStandBtn.layer.maskedCorners = [.layerMinXMinYCorner, .layerMinXMaxYCorner]
personalStandBtn.setTitle("个人认证", for: .normal)
personalStandBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
personalStandBtn.titleLabel?.font = UIFont.init(name: "PingFangSC-Medium", size: 14)
personalStandBtn.addTarget(self, action: #selector(personalStandBtnAction), for: .touchUpInside)
return personalStandBtn
}()
///未认证-企业认证 按钮
lazy var enterpriseStandBtn: UIButton = {
let enterpriseStandBtn = UIButton(type: .custom)
enterpriseStandBtn.layer.cornerRadius = 19.5
enterpriseStandBtn.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMaxXMaxYCorner]
enterpriseStandBtn.setTitle("企业认证", for: .normal)
enterpriseStandBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
enterpriseStandBtn.titleLabel?.font = UIFont.init(name: "PingFangSC-Medium", size: 14)
enterpriseStandBtn.addTarget(self, action: #selector(enterpriseStandBtnAction), for: .touchUpInside)
return enterpriseStandBtn
}()
//上滑更多Gif
lazy var upMoreGIF: UIImageView = {
let upMoreGIF = UIImageView()
upMoreGIF.frame = CGRect(x: self.width - 50, y: 0, width: 50, height: 30)
return upMoreGIF
}()
//下滑更多Gif
lazy var downMoreGIF: UIImageView = {
let downMoreGIF = UIImageView()
downMoreGIF.frame = CGRect(x: self.width - 50, y: 0, width: 96, height: 30)
return downMoreGIF
}()
///已认证-前置视图卡片容器
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
//上滑 下滑引导gif
upMoreGIF.kf.setImage(with: URL(string: newValue!.upGuideImg))
downMoreGIF.kf.setImage(with: URL(string: newValue!.downGuideImg))
if idModel?.id == 9{
//电商 ,隐藏上滑下滑gif
upMoreGIF.isHidden = true
downMoreGIF.isHidden = true
self.addStandBtn.backgroundColor = HexColor(newValue!.backgroundColor)
self.addStandBtn.isHidden = false
self.personalStandBtn.isHidden = true
self.enterpriseStandBtn.isHidden = true
}else{
//非电商 ,显示上滑下滑gif
upMoreGIF.isHidden = false
downMoreGIF.isHidden = false
self.addStandBtn.isHidden = true
self.personalStandBtn.isHidden = false
self.enterpriseStandBtn.isHidden = false
}
//个人认证,企业认证
personalStandBtn.backgroundColor = HexColor(newValue!.atPersonageColour)
enterpriseStandBtn.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() {
//跳转到电商认证页面
self.pushStandVC()
}
@objc func personalStandBtnAction() {
//跳转到 个人认证页面
self.pushStandVC()
}
@objc func enterpriseStandBtnAction() {
//跳转到 企业认证页面
self.pushStandVC()
}
func pushStandVC(){
//跳转到 个人认证&企业认证 页面
if _idModel!.id == 9 {
showLoading(message: "")
CNLiveMineViewModel.requestApplyShopInfo { [weak self] result, respStatue in
if respStatue == .success {
navigationViewController().pushViewController(CNLiveMineShopViewController.init(showType: .one, listModel: (self?.idModel)!, tempArray: []), animated: pushAnimated)
}
}
}else{
navigationViewController().pushViewController(CNLiveMineInputViewController.init(listModel: self._idModel!, authType: .person), animated: pushAnimated)
}
}
}
///反面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);
}
}