宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
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
//
//  UserAnnotationView.swift
//  QuanKeTong
//
//  Created by alvin_y on 2019/6/13.
//  Copyright © 2019 yang-wang. All rights reserved.
//
 
import UIKit
 
class UserAnnotationView: MAAnnotationView {
    
    /// 气泡
    let calloutView = UserCalloutView.instance()
    
    /// 气泡点击回调
    var onTapCallout:((_ annotation: MAAnnotation) -> Void)?
    
    /// 着色
    var yy_tintColor = UIColor.color(hexString: "#333333")
    
    /// 字体
    var yy_font = UIFont.systemFont(ofSize: 12)
    
    /// 着色
    var yy_isTintColor = false
    
    /// 标题
    var title: String = "" {
        didSet{
            calloutView.yy_isTintColor  = yy_isTintColor
            calloutView.yy_tintColor  = yy_tintColor
            calloutView.yy_font = yy_font
            calloutView.title = title
            calloutView.isHidden = title == ""
        }
    }
    
    override init!(annotation: MAAnnotation!, reuseIdentifier: String!) {
        super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)
        setup()
    }
    
    
    func setup()  {
        calloutView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(calloutViewActtion)))
        self.addSubview(calloutView)
        calloutView.title = title
        calloutView.isHidden = title == ""
        calloutView.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().offset(-36)
            make.size.greaterThanOrEqualTo(CGSize(width: 20, height: 10))
        }
    }
    
    
    /// 气泡点击
    @objc func calloutViewActtion() {
        onTapCallout?(self.annotation)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}