CNHomePageGuideView.swift
2.84 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
//
// CNHomePageGuideView.swift
// metaCode
//
// Created by daojian on 2023/6/7.
// 认证-首页引导
import Foundation
typealias skipGuideBlock = ()->Void
class CNHomePageGuideView: UIView{
///跳过引导事件回调
var skipAction: skipGuideBlock?
lazy var skipButtom: UIButton = {
let skipButtom = UIButton(type: .custom)
skipButtom.frame = CGRect(x: 0, y: 0, width: 90, height: 30)
skipButtom.right = self.width - 30
skipButtom.top = KStatusBarHeight + 30
skipButtom.setTitle("跳过引导", for: .normal)
skipButtom.setTitleColor(.white, for: .normal)
skipButtom.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .medium)
skipButtom.clipsToBounds = true
skipButtom.layer.cornerRadius = skipButtom.height/2
skipButtom.layer.borderColor = UIColor("#979797")?.cgColor
skipButtom.layer.borderWidth = 0.5
return skipButtom
}()
lazy var bottomLabel: UILabel = {
let bottomLabel = UILabel.init(frame: CGRect(x: 0, y: 0, width: 150, height: 20))
bottomLabel.textColor = .white
bottomLabel.font = UIFont.systemFont(ofSize: 18, weight: .medium)
bottomLabel.textAlignment = .center
return bottomLabel
}()
override init(frame: CGRect) {
super.init(frame: frame)
self.initUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func initUI(){
self.addSubview(self.skipButtom)
self.backgroundColor = .black.withAlphaComponent(0.7)
self.isUserInteractionEnabled = false
//通过设置mask透明区域来实现镂空效果
let path:UIBezierPath = UIBezierPath.init(rect: UIScreen.main.bounds)
//rect 首页被镂空的区域
let W = MainViewW
let H = W*1.5
let rect = CGRectMake(LeftGap, KSreenHeight*0.16,W, H)
let appendPath: UIBezierPath = UIBezierPath.init(roundedRect: rect, cornerRadius: 20)
path.append(appendPath.reversing())
let shapeLayer: CAShapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath;
self.layer.mask = shapeLayer
//更新bottomLabel位置
self.bottomLabel.centerX = self.centerX
self.bottomLabel.top = CGRectGetMaxY(rect) + 20
self.addSubview(self.bottomLabel)
}
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if((self.skipButtom.layer.hitTest(point)) != nil){
// print("点击了跳过")
self.skipAction!()
}
//让事件响应链进行执行
return super.hitTest(point, with: event)
}
func setBottomText(text: String)->Void{
self.bottomLabel.text = text
}
}