AlertSheetView.swift 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // AlertSheetView.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/4/17.
  6. // Copyright © 2019 南鑫林. All rights reserved.
  7. //
  8. import UIKit
  9. import FWPopupView
  10. class AlertSheetView: NSObject {
  11. /// 自定义Alert弹框样式
  12. ///
  13. /// - Parameters:
  14. /// - title: 标题
  15. /// - detailTitle: 副标题
  16. /// - confirmBlock: 完成回调
  17. /// - cancelBlock: 取消回调
  18. /// - Returns: FWAlertView
  19. class func alert(title: String = "",detailTitle:String = "",cancelTitle:String = "取消",sureTitle:String = "确定",cancelBlock: FWPopupItemClickedBlock? = nil, confirmBlock: FWPopupItemClickedBlock? = nil) {
  20. // 注意:此时“确定”按钮是不让按钮自己隐藏的
  21. let items = [FWPopupItem(title: cancelTitle, itemType: .normal, isCancel: true, canAutoHide: true, itemTitleColor: k333333Color, itemBackgroundColor: nil, itemClickedBlock: cancelBlock),
  22. FWPopupItem(title: sureTitle, itemType: .normal, isCancel: false, canAutoHide: true, itemTitleColor: kFFA42FColor, itemBackgroundColor: nil, itemClickedBlock: confirmBlock)]
  23. // 演示:修改参数
  24. let vProperty = FWAlertViewProperty()
  25. vProperty.alertViewWidth = max(UIScreen.main.bounds.width * 0.65, 275)
  26. vProperty.titleFontSize = 18.0
  27. vProperty.titleColor = UIColor.black
  28. vProperty.detailFontSize = 15.0
  29. vProperty.detailColor = k999999Color
  30. vProperty.buttonFontSize = 18.0
  31. vProperty.maskViewColor = UIColor(white: 0, alpha: 0.5)
  32. vProperty.touchWildToHide = "0"
  33. // 还有很多参数可设置...
  34. let alertView = FWAlertView.alert(title: title, detail: detailTitle, inputPlaceholder: nil, keyboardType: .default, isSecureTextEntry: false, customView: nil, items: items, vProperty: vProperty)
  35. alertView.show()
  36. }
  37. /// 自定义Alert弹框样式
  38. ///
  39. /// - Parameters:
  40. /// - title: 标题
  41. /// - confirmBlock: 完成回调
  42. /// - cancelBlock: 取消回调
  43. /// - Returns: FWAlertView
  44. class func alert(title: String = "",cancelTitle:String = "取消",sureTitle:String = "确定",cancelBlock: FWPopupItemClickedBlock? = nil, confirmBlock: FWPopupItemClickedBlock? = nil) {
  45. // 注意:此时“确定”按钮是不让按钮自己隐藏的
  46. let items = [FWPopupItem(title: cancelTitle, itemType: .normal, isCancel: true, canAutoHide: true, itemTitleColor: k333333Color, itemBackgroundColor: nil, itemClickedBlock: cancelBlock),
  47. FWPopupItem(title: sureTitle, itemType: .normal, isCancel: false, canAutoHide: true, itemTitleColor: kFFA42FColor, itemBackgroundColor: nil, itemClickedBlock: confirmBlock)]
  48. // 演示:修改参数
  49. let vProperty = FWAlertViewProperty()
  50. vProperty.alertViewWidth = max(UIScreen.main.bounds.width * 0.65, 275)
  51. vProperty.titleFontSize = 18.0
  52. vProperty.titleColor = UIColor.black
  53. vProperty.detailFontSize = 15.0
  54. vProperty.detailColor = k999999Color
  55. vProperty.buttonFontSize = 18.0
  56. vProperty.maskViewColor = UIColor(white: 0, alpha: 0.5)
  57. vProperty.touchWildToHide = "0"
  58. // 还有很多参数可设置...
  59. let alertView = FWAlertView.alert(title: title, detail: nil, inputPlaceholder: nil, keyboardType: .default, isSecureTextEntry: false, customView: nil, items: items, vProperty: vProperty)
  60. alertView.show()
  61. }
  62. typealias SureClosure = (_ province :Province ,_ city : City ,_ area :Area) -> Void
  63. /// 自定义sheet省市区
  64. class func sheetProvinceCityAreaView(sureClosure:@escaping (Province ,City ,Area) -> Void) {
  65. let provinceCityAreaView = ProvinceCityAreaView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: kSafeTabBarHeight + 340))
  66. let vProperty = FWPopupViewProperty()
  67. vProperty.popupCustomAlignment = .bottomCenter
  68. vProperty.popupAnimationType = .frame
  69. vProperty.maskViewColor = UIColor(white: 0, alpha: 0.5)
  70. vProperty.touchWildToHide = "1"
  71. vProperty.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  72. vProperty.animationDuration = 0.5
  73. provinceCityAreaView.vProperty = vProperty
  74. provinceCityAreaView.show()
  75. provinceCityAreaView.sureClosure = {
  76. (province :Province , city : City , area :Area) in
  77. provinceCityAreaView.hide(popupDidDisappearBlock: { (popupView) in
  78. sureClosure(province, city,area)
  79. })
  80. }
  81. }
  82. /// 自定义支付View
  83. class func payAlertSheetView(paymentAmount:String, cancelClosure:@escaping () -> Void, sureClosure:@escaping (_ pType: PayType) -> Void) {
  84. let payView = CommonPayView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: kSafeTabBarHeight + 300))
  85. payView.paymentAmount = paymentAmount
  86. let vProperty = FWPopupViewProperty()
  87. vProperty.popupCustomAlignment = .bottomCenter
  88. vProperty.popupAnimationType = .frame
  89. vProperty.maskViewColor = UIColor(white: 0, alpha: 0.5)
  90. vProperty.touchWildToHide = "0"
  91. vProperty.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  92. vProperty.animationDuration = 0.3
  93. payView.vProperty = vProperty
  94. payView.show()
  95. payView.disTransBlock = {
  96. cancelClosure()
  97. payView.hide()
  98. }
  99. payView.confirmPayBlock = { payType in
  100. sureClosure(payType)
  101. payView.hide()
  102. }
  103. }
  104. /// 自定义评论View
  105. class func commentAlertSheetView(postId:Int, cancelClosure:@escaping () -> Void, sureClosure:@escaping (_ pType: PayType) -> Void) {
  106. let commentView = CommunityAllCommentView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: kSafeTabBarHeight + 500))
  107. commentView.postId = postId
  108. let vProperty = FWPopupViewProperty()
  109. vProperty.popupCustomAlignment = .bottomCenter
  110. vProperty.popupAnimationType = .frame
  111. vProperty.maskViewColor = UIColor(white: 0, alpha: 0.5)
  112. vProperty.touchWildToHide = "0"
  113. vProperty.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  114. vProperty.animationDuration = 0.3
  115. commentView.vProperty = vProperty
  116. commentView.show()
  117. commentView.disTransBlock = {
  118. cancelClosure()
  119. commentView.hide()
  120. }
  121. commentView.confirmPayBlock = { payType in
  122. sureClosure(payType)
  123. commentView.hide()
  124. }
  125. }
  126. /// 分享
  127. class func sheetShareView() {
  128. let view = ShareView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: kSafeTabBarHeight + 250))
  129. let vProperty = FWPopupViewProperty()
  130. vProperty.popupCustomAlignment = .bottomCenter
  131. vProperty.popupAnimationType = .frame
  132. vProperty.maskViewColor = UIColor(white: 0, alpha: 0.5)
  133. vProperty.touchWildToHide = "1"
  134. vProperty.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  135. vProperty.animationDuration = 0.2
  136. view.vProperty = vProperty
  137. view.show()
  138. }
  139. /// 单个选择器
  140. class func sheetPickViewOneComponentsView(titles:[String],title:String,height:CGFloat,sureClosure:((_ row: Int,_ value:String) -> Void)?) {
  141. let view = PickViewOneComponentsView(titles: titles,title: title)
  142. view.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: height * kScaleWidth + kSafeTabBarHeight)
  143. let vProperty = FWPopupViewProperty()
  144. vProperty.popupCustomAlignment = .bottomCenter
  145. vProperty.popupAnimationType = .frame
  146. vProperty.maskViewColor = UIColor(white: 0, alpha: 0.5)
  147. vProperty.touchWildToHide = "1"
  148. view.vProperty = vProperty
  149. view.sureClosure = { (row,value) in
  150. sureClosure!(row!,value!)
  151. view.hide()
  152. }
  153. view.show()
  154. }
  155. }
  156. // MARK: - Sheet
  157. extension AlertSheetView {
  158. class func sheetDislike(dislike:Int,y:CGFloat,sureClosure:@escaping ((CardContentUserDisLikeView) -> Void)) {
  159. let view = CardContentUserDisLikeView(frame: CGRect(x: 0, y: 0, width: kScreenWidth-28, height: 50))
  160. view.isDisLike = dislike
  161. let vProperty = FWPopupViewProperty()
  162. if y > kScreenHeight/2 {
  163. vProperty.popupCustomAlignment = .bottomCenter
  164. vProperty.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: kScreenHeight-y+29, right: 0)
  165. }else {
  166. vProperty.popupCustomAlignment = .topCenter
  167. vProperty.popupViewEdgeInsets = UIEdgeInsets(top: y+51, left: 0, bottom: 0, right: 0)
  168. }
  169. vProperty.popupAnimationType = .scale
  170. vProperty.maskViewColor = UIColor(white: 0, alpha: 0.5)
  171. vProperty.touchWildToHide = "1"
  172. view.vProperty = vProperty
  173. view.disLikeButtonClosure = {
  174. view.hide()
  175. sureClosure(view)
  176. }
  177. view.show()
  178. }
  179. }