YMAlert.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // YMAlert.h
  3. // yuemoClient
  4. //
  5. // Created by YoMi on 2023/11/6.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import <UIKit/UIKit.h>
  9. #import "YMPopupView.h"
  10. NS_ASSUME_NONNULL_BEGIN
  11. @class YMAlert;
  12. typedef YMAlert * _Nonnull (^YMAlertString)(NSString * string);
  13. typedef YMAlert * _Nonnull (^YMAlertView)(UIView * view);
  14. typedef YMAlert * _Nonnull (^YMAlertCustomView)(YmViewBlock block);
  15. typedef YMAlert * _Nonnull (^YMAlertColor)(UIColor * color);
  16. typedef YMAlert * _Nonnull (^YMAlertDelegate)(id<YMPopupViewProtocol> delegate);
  17. typedef YMAlert * _Nonnull (^YMAlertPositionStyle)(YMPositionStyle style);
  18. typedef YMAlert * _Nonnull (^YMAlertPopStyle)(YMPopupStyle style);
  19. typedef YMAlert * _Nonnull (^YMAlertDismissStyle)(YMDismissStyle style);
  20. typedef YMAlert * _Nonnull (^YMAlertDragStyle)(YMDragStyle style);
  21. typedef YMAlert * _Nonnull (^YMAlertSweepStyle)(YMSweepStyle style);
  22. typedef YMAlert * _Nonnull (^YMAlertSweepDismissStyle)(YMSweepDismissStyle style);
  23. typedef YMAlert * _Nonnull (^YMAlertInterval)(NSTimeInterval num);
  24. typedef YMAlert * _Nonnull (^YMAlertFloat)(CGFloat num);
  25. typedef YMAlert * _Nonnull (^YMAlertBOOL)(BOOL is);
  26. typedef YMAlert * _Nonnull (^YMAlertCorner)(UIRectCorner corner);
  27. typedef YMAlert * _Nonnull (^YMAlertBlock)(YmVoidBlock block);
  28. typedef YMAlert * _Nonnull (^YMAlertVoid)(void);
  29. typedef YMAlert * _Nonnull (^YMAlertPointBlock)(YmPointBlock block);
  30. typedef YMAlert * _Nonnull (^YMAlertKeyBoardChangeBlock)(YmKeyBoardChangeBlock block);
  31. typedef YMAlert * _Nonnull (^YMAlertAlertCountDownBlock)(YmAlertCountDownBlock block);
  32. @interface YMAlert : NSObject
  33. /// 初始化 alert
  34. + (instancetype)alert;
  35. #pragma mark - =================== 便利方法 ===================
  36. /// 获取全局(整个app内)所有popView
  37. + (NSArray <YMPopupView *>*)getAllPopView;
  38. /// 获取当前页面所有popView
  39. + (NSArray <YMPopupView *>*)getAllPopViewForParentView:(UIView *)parentView;
  40. /// 获取当前页面指定编队的所有popView
  41. + (NSArray <YMPopupView *>*)getAllPopViewForPopView:(UIView *)popView;
  42. /// 读取popView (有可能会跨编队读取弹窗)
  43. + (YMPopupView *)getPopViewForKey:(NSString *)key;
  44. /// 移除所有的 popview
  45. + (void)dismissAllAlert:(YmVoidBlock)complete;
  46. /// 移除最后添加的 popview
  47. + (void)dismissAlertComplete:(YmVoidBlock)complete;
  48. /// 移除指定 YMAlert 的 popview
  49. + (void)dismissAlertForAlert:(YMAlert *)alert complete:(YmVoidBlock)complete;
  50. /// 移除指定 key 的 popview
  51. + (void)dismissAlertForKey:(NSString *)key complete:(YmVoidBlock)complete;
  52. /// 移除指定 popview 的 popview
  53. + (void)dismissAlertForPopView:(YMPopupView *)popView complete:(YmVoidBlock)complete;
  54. #pragma mark - 基础属性
  55. /// 代理 支持多代理
  56. @property (nonatomic , copy , readonly ) YMAlertDelegate delegate;
  57. /// 标识 默认为空
  58. @property (nonatomic , copy , readonly ) YMAlertString identifier;
  59. /// 弹窗容器
  60. @property (nonatomic , copy , readonly ) YMAlertView parentView;
  61. /// 自定义view
  62. @property (nonatomic , copy , readonly ) YMAlertCustomView currCustomView;
  63. /// 弹窗位置 默认YMPositionStyleCenter
  64. @property (nonatomic , copy , readonly ) YMAlertPositionStyle positionStyle;
  65. /// 显示时动画弹窗样式 默认YMPopupStyleFade
  66. @property (nonatomic , copy , readonly ) YMAlertPopStyle popStyle;
  67. /// 移除时动画弹窗样式 默认YMDismissStyleFade
  68. @property (nonatomic , copy , readonly ) YMAlertDismissStyle dismissStyle;
  69. /// 显示时动画时长,> 0。不设置则使用默认的动画时长 设置成YMPopupStyleNO, 该属性无效
  70. @property (nonatomic , copy , readonly ) YMAlertInterval popDuration;
  71. /// 隐藏时动画时长,>0。不设置则使用默认的动画时长 设置成YMDismissStyleNO, 该属性无效
  72. @property (nonatomic , copy , readonly ) YMAlertInterval dismissDuration;
  73. /// 弹窗水平方向(X)偏移量校准 默认0
  74. @property (nonatomic , copy , readonly ) YMAlertFloat adjustX;
  75. /// 弹窗垂直方向(Y)偏移量校准 默认0
  76. @property (nonatomic , copy , readonly ) YMAlertFloat adjustY;
  77. /// 背景颜色 默认rgb(0,0,0) 透明度0.3
  78. @property (nonatomic , copy , readonly ) YMAlertColor bgColor;
  79. /// 显示时背景的透明度,取值(0.0~1.0),默认为0.3
  80. @property (nonatomic , copy , readonly ) YMAlertFloat bgAlpha;
  81. /// 是否隐藏背景 默认NO
  82. @property (nonatomic , copy , readonly ) YMAlertBOOL isHideBg;
  83. /// 显示时点击背景是否移除弹窗,默认为NO。
  84. @property (nonatomic , copy , readonly ) YMAlertBOOL isClickBgDismiss;
  85. /// 是否监听屏幕旋转,默认为YES
  86. @property (nonatomic , copy , readonly ) YMAlertBOOL isObserverScreenRotation;
  87. /// 是否支持点击回馈 默认NO (暂时关闭)
  88. @property (nonatomic , copy , readonly ) YMAlertBOOL isClickFeedback;
  89. /// 是否规避键盘 默认YES
  90. @property (nonatomic , copy , readonly ) YMAlertBOOL isAvoidKeyboard;
  91. /// 弹窗和键盘的距离 默认10
  92. @property (nonatomic , copy , readonly ) YMAlertFloat avoidKeyboardSpace;
  93. /// 显示多长时间 默认0 不会消失
  94. @property (nonatomic , copy , readonly ) YMAlertInterval showTime;
  95. /// 自定view圆角方向设置 默认UIRectCornerAllCorners 当cornerRadius>0时生效
  96. @property (nonatomic , copy , readonly ) YMAlertCorner rectCorners;
  97. /// 自定义view圆角大小, 默认 0
  98. @property (nonatomic , copy , readonly ) YMAlertFloat cornerRadius;
  99. /// 弹出震动反馈 默认NO iOS10+ 系统才有此效果
  100. @property (nonatomic , copy , readonly ) YMAlertBOOL isImpactFeedback;
  101. #pragma mark - 群组相关属性
  102. /// 群组标识 统一给弹窗编队 方便独立管理 默认为nil,统一全局处理
  103. @property (nonatomic , copy , readonly ) YMAlertString groupId;
  104. /// 是否堆叠 默认NO 如果是YES priority优先级不生效
  105. @property (nonatomic , copy , readonly ) YMAlertBOOL isStack;
  106. /// 单显示 默认NO 只会显示优先级最高的popView
  107. @property (nonatomic , copy , readonly ) YMAlertBOOL isSingle;
  108. /// 优先级 范围0~1000 (默认0,遵循先进先出) isStack和isSingle为NO的时候生效
  109. @property (nonatomic , copy , readonly ) YMAlertFloat priority;
  110. #pragma mark - 拖拽手势相关属性
  111. /// 拖拽方向 默认 不可拖拽
  112. @property (nonatomic , copy , readonly ) YMAlertDragStyle dragStyle;
  113. /// X轴或者Y轴拖拽移除临界距离 范围(0 ~ +∞) 默认0 不拖拽移除 基使用于dragStyle
  114. @property (nonatomic , copy , readonly ) YMAlertFloat dragDistance;
  115. /// 拖拽移除动画类型 默认同dismissStyle
  116. @property (nonatomic , copy , readonly ) YMAlertDismissStyle dragDismissStyle;
  117. /// 拖拽消失动画时间 默认同 dismissDuration
  118. @property (nonatomic , copy , readonly ) YMAlertInterval dragDismissDuration;
  119. /// 拖拽复原动画时间 默认0.25s
  120. @property (nonatomic , copy , readonly ) YMAlertInterval dragReboundTime;
  121. /// 轻扫方向 默认 不可轻扫 前提开启dragStyle
  122. @property (nonatomic , copy , readonly ) YMAlertSweepStyle sweepStyle;
  123. /// 轻扫速率 控制轻扫移除 默认1000 基于使用sweepStyle
  124. @property (nonatomic , copy , readonly ) YMAlertFloat swipeVelocity;
  125. /// 轻扫移除的动画 默认YMSweepDismissStyleVelocity
  126. @property (nonatomic , copy , readonly ) YMAlertSweepDismissStyle sweepDismissStyle;
  127. #pragma mark - 交互回调
  128. /// 点击背景
  129. @property (nonatomic , copy , readonly ) YMAlertBlock bgClickBlock;
  130. /// 长按背景
  131. @property (nonatomic , copy , readonly ) YMAlertBlock bgLongPressBlock;
  132. /// 弹窗pan手势偏移量
  133. @property (nonatomic , copy , readonly ) YMAlertPointBlock panOffsetBlock;
  134. #pragma mark - 以下键盘弹出/收起 第三方键盘会多次回调(百度,搜狗测试得出), 原生键盘回调一次
  135. /// 键盘将要弹出
  136. @property (nonatomic , copy , readonly ) YMAlertBlock keyboardWillShowBlock;
  137. /// 键盘弹出完毕
  138. @property (nonatomic , copy , readonly ) YMAlertBlock keyboardDidShowBlock;
  139. /// 键盘frame将要改变
  140. @property (nonatomic , copy , readonly ) YMAlertKeyBoardChangeBlock keyboardFrameWillChangeBlock;
  141. /// 键盘frame改变完毕
  142. @property (nonatomic , copy , readonly ) YMAlertKeyBoardChangeBlock keyboardFrameDidChangeBlock;
  143. /// 键盘将要收起
  144. @property (nonatomic , copy , readonly ) YMAlertBlock keyboardWillHideBlock;
  145. /// 键盘收起完毕
  146. @property (nonatomic , copy , readonly ) YMAlertBlock keyboardDidHideBlock;
  147. #pragma mark - 生命周期回调(Block)
  148. /// 将要显示 回调
  149. @property (nonatomic , copy , readonly ) YMAlertBlock popViewWillPopBlock;
  150. /// 已经显示完毕 回调
  151. @property (nonatomic , copy , readonly ) YMAlertBlock popViewDidPopBlock;
  152. /// 将要开始移除 回调
  153. @property (nonatomic , copy , readonly ) YMAlertBlock popViewWillDismissBlock;
  154. /// 已经移除完毕 回调
  155. @property (nonatomic , copy , readonly ) YMAlertBlock popViewDidDismissBlock;
  156. /// 倒计时 回调
  157. @property (nonatomic , copy , readonly ) YMAlertAlertCountDownBlock popViewCountDownBlock;
  158. /// 弹出
  159. @property (nonatomic , copy , readonly ) YMAlertVoid pop;
  160. /// 消失
  161. @property (nonatomic , copy , readonly ) YMAlertVoid dismiss;
  162. @property (nonatomic , weak , readonly ) YMPopupView * popView;
  163. @end
  164. NS_ASSUME_NONNULL_END