QSLFriendAddAlertView.swift 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. //
  2. // QSLFriendAddAlertView.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by mac on 2024/4/12.
  6. //
  7. import UIKit
  8. class QSLFriendAddAlertView: UIView {
  9. var viewController: UIViewController?
  10. var clickClosure: (() -> Void)?
  11. lazy var addBgView: UIView = {
  12. let view = UIView()
  13. view.backgroundColor = UIColor.hexStringColor(hexString: "#000000", alpha: 0.5)
  14. view.alpha = 0
  15. let tap = UITapGestureRecognizer(target: self, action: #selector(removeView))
  16. view.addGestureRecognizer(tap)
  17. return view
  18. }()
  19. lazy var addContentView: UIView = {
  20. let view = UIView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH - 100))
  21. view.backgroundColor = .white
  22. view.addCorner(conrners: [.topLeft, .topRight], radius: 20)
  23. return view
  24. }()
  25. lazy var addCloseButton: UIButton = {
  26. let button = UIButton(type: .custom)
  27. button.image(UIImage(named: "public_btn_close_AAA"))
  28. button.addTarget(self, action: #selector(removeView), for: .touchUpInside)
  29. return button
  30. }()
  31. lazy var addBgImageView: UIImageView = {
  32. let imageView = UIImageView()
  33. imageView.image = UIImage(named: "friends_add_bg")
  34. return imageView
  35. }()
  36. lazy var addMainView: UIView = {
  37. let scale = 1080.0 / 860.0
  38. let topBgHeight = qsl_kScreenW / scale
  39. let mainViewHeight = qsl_kScreenH - topBgHeight - 50.0
  40. let view = UIView(frame: CGRect(x: 0, y: topBgHeight - 50, width: qsl_kScreenW, height: mainViewHeight))
  41. view.backgroundColor = .white
  42. let aPath = UIBezierPath()
  43. aPath.lineWidth = 1.0
  44. aPath.lineCapStyle = .round
  45. aPath.lineJoinStyle = .round
  46. aPath.move(to: CGPoint(x: 0, y: 20))
  47. aPath.addQuadCurve(to: CGPoint(x: qsl_kScreenW, y: 20), controlPoint: CGPoint(x: qsl_kScreenW / 2, y: -20))
  48. aPath.addLine(to: CGPoint(x: qsl_kScreenW, y: mainViewHeight))
  49. aPath.addLine(to: CGPoint(x: 0, y: mainViewHeight))
  50. aPath.addLine(to: CGPoint(x: 0, y: 20))
  51. let maskLayer = CAShapeLayer()
  52. maskLayer.frame = view.bounds
  53. maskLayer.path = aPath.cgPath
  54. view.layer.mask = maskLayer
  55. return view
  56. }()
  57. lazy var addMainTitleLabel: UILabel = {
  58. let label = UILabel()
  59. label.mediumFont(20)
  60. label.textColor = QSLColor.textColor_333
  61. label.text = "添加好友"
  62. return label
  63. }()
  64. lazy var addMainSubTitleLabel: UILabel = {
  65. let label = UILabel()
  66. label.font(13)
  67. label.textColor = QSLColor.Color_888
  68. label.text = "查看实时定位,开启轨迹守护"
  69. return label
  70. }()
  71. lazy var addMainPhoneView: UIView = {
  72. let view = UIView()
  73. view.backgroundColor = QSLColor.backGroundColor
  74. view.addRadius(radius: 6)
  75. return view
  76. }()
  77. lazy var addMainPhoneTextField: UITextField = {
  78. let textF = UITextField()
  79. textF.font = UIFont.textF(16)
  80. textF.textColor = QSLColor.textColor_333
  81. textF.keyboardType = .phonePad
  82. textF.textAlignment = .left
  83. textF.maxTextNumber = 11
  84. textF.setPlaceholderAttribute(font: UIFont.textF(16), color: QSLColor.textColor_AAA)
  85. textF.placeholder = "输入手机号码 查看定位"
  86. return textF
  87. }()
  88. lazy var addMainAddrBookBtn: UIButton = {
  89. let button = UIButton(type: .custom)
  90. button.font(16)
  91. button.textColor(QSLColor.textColor_333)
  92. button.title("通讯录")
  93. return button
  94. }()
  95. lazy var lineIcon: UIImageView = {
  96. let _lineIcon = UIImageView()
  97. _lineIcon.image = UIImage.image(color: UIColor.hexStringColor(hexString: "#AAAAAA", alpha: 0.4), size: CGSize(width: 1, height: 24))
  98. return _lineIcon
  99. }()
  100. lazy var addMainSearchBtn: UIButton = {
  101. let button = UIButton.normal()
  102. button.title("立即添加")
  103. button.addRadius(radius: 22)
  104. button.isEnabled = false
  105. return button
  106. }()
  107. lazy var addMainTipsLabel: UILabel = {
  108. let label = UILabel()
  109. label.numberOfLines = 0
  110. label.textAlignment = .center
  111. label.font(12)
  112. label.textColor = QSLColor.textColor_D1
  113. label.text = "温馨提示:文本在线配置内容,直接使用添加好友文本配置接口。"
  114. return label
  115. }()
  116. class func show(vc: UIViewController, clickClosure: @escaping () -> Void) {
  117. let window = QSLFriendAddAlertView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
  118. window.viewController = vc
  119. window.clickClosure = clickClosure
  120. vc.view.addSubview(window)
  121. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) {
  122. window.addBgView.alpha = 1
  123. window.addContentView.qsl_y = 100
  124. }
  125. }
  126. override init(frame: CGRect) {
  127. super.init(frame: frame)
  128. self.setUpUI()
  129. }
  130. required init?(coder: NSCoder) {
  131. fatalError("init(coder:) has not been implemented")
  132. }
  133. // 关闭本view
  134. @objc func removeView() {
  135. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
  136. self?.addBgView.alpha = 0
  137. self?.addContentView.qsl_y = QSLConst.qsl_kScreenH
  138. } completion: { [weak self] finished in
  139. self?.removeFromSuperview()
  140. }
  141. }
  142. }
  143. extension QSLFriendAddAlertView {
  144. func setUpUI() {
  145. self.backgroundColor = .clear
  146. addSubview(addBgView)
  147. addSubview(addContentView)
  148. addContentView.addSubview(addBgImageView)
  149. addContentView.addSubview(addCloseButton)
  150. addContentView.addSubview(addMainView)
  151. addMainView.addSubview(addMainTitleLabel)
  152. addMainView.addSubview(addMainSubTitleLabel)
  153. addMainView.addSubview(addMainPhoneView)
  154. addMainPhoneView.addSubview(addMainAddrBookBtn)
  155. addMainPhoneView.addSubview(lineIcon)
  156. addMainPhoneView.addSubview(addMainPhoneTextField)
  157. addMainView.addSubview(addMainSearchBtn)
  158. addMainView.addSubview(addMainTipsLabel)
  159. addBgView.snp.makeConstraints { make in
  160. make.edges.equalTo(0)
  161. }
  162. addContentView.snp.makeConstraints { make in
  163. make.top.equalTo(100)
  164. make.left.right.bottom.equalTo(0)
  165. }
  166. addContentView.qsl_y = qsl_kScreenH
  167. let scale = 1080.0 / 860.0
  168. let topBgHeight = qsl_kScreenW / scale
  169. addBgImageView.snp.makeConstraints { make in
  170. make.left.top.right.equalTo(0)
  171. make.height.equalTo(topBgHeight)
  172. }
  173. addCloseButton.snp.makeConstraints { make in
  174. make.size.equalTo(CGSize(width: 24, height: 24))
  175. make.top.equalTo(16)
  176. make.right.equalTo(-20)
  177. }
  178. addMainTitleLabel.snp.makeConstraints { make in
  179. make.top.equalTo(56)
  180. make.centerX.equalTo(addMainView.snp.centerX)
  181. }
  182. addMainSubTitleLabel.snp.makeConstraints { make in
  183. make.top.equalTo(addMainTitleLabel.snp.bottom).offset(2)
  184. make.centerX.equalTo(addMainView.snp.centerX)
  185. }
  186. addMainPhoneView.snp.makeConstraints { make in
  187. make.left.equalTo(24)
  188. make.right.equalTo(-24)
  189. make.height.equalTo(56)
  190. make.top.equalTo(addMainSubTitleLabel.snp.bottom).offset(20)
  191. }
  192. addMainAddrBookBtn.snp.makeConstraints { make in
  193. make.top.bottom.right.equalTo(0)
  194. make.width.equalTo(72)
  195. }
  196. lineIcon.snp.makeConstraints { make in
  197. make.right.equalTo(addMainAddrBookBtn.snp.left)
  198. make.centerY.equalTo(addMainPhoneView.snp.centerY)
  199. }
  200. addMainPhoneTextField.snp.makeConstraints { make in
  201. make.left.equalTo(16)
  202. make.right.equalTo(lineIcon.qsl_left).offset(-16)
  203. make.top.bottom.equalTo(0)
  204. }
  205. addMainSearchBtn.snp.makeConstraints { make in
  206. make.size.equalTo(CGSize(width: 200, height: 44))
  207. make.top.equalTo(addMainPhoneView.snp.bottom).offset(36)
  208. make.centerX.equalTo(snp.centerX)
  209. }
  210. addMainTipsLabel.snp.makeConstraints { make in
  211. make.left.equalTo(60)
  212. make.right.equalTo(-60)
  213. make.bottom.equalTo(-QSLConst.qsl_kTabbarBottom - 20)
  214. }
  215. }
  216. }