MISFloatingBall.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // MISFloatingBall.h
  3. // MISFloatingBall
  4. //
  5. // Created by Mistletoe on 2017/4/22.
  6. // Copyright © 2017年 Mistletoe. All rights reserved.
  7. // 悬浮球
  8. #import <UIKit/UIKit.h>
  9. NS_ASSUME_NONNULL_BEGIN
  10. /**< 靠边策略(默认所有边框均可停靠) */
  11. typedef NS_ENUM(NSUInteger, MISFloatingBallEdgePolicy) {
  12. MISFloatingBallEdgePolicyAllEdge = 0, /**< 所有边框都可
  13. (符合正常使用习惯,滑到某一位置时候才上下停靠,参见系统的 assistiveTouch) */
  14. MISFloatingBallEdgePolicyLeftRight, /**< 只能左右停靠 */
  15. MISFloatingBallEdgePolicyUpDown, /**< 只能上下停靠 */
  16. };
  17. typedef NS_ENUM(NSUInteger, MISFloatingBallContentType) {
  18. MISFloatingBallContentTypeImage = 0, // 图片
  19. MISFloatingBallContentTypeText, // 文字
  20. MISFloatingBallContentTypeCustomView // 自定义视图(添加到上方的自定义视图默认 userInteractionEnabled = NO)
  21. };
  22. typedef struct MISEdgeRetractConfig {
  23. CGPoint edgeRetractOffset; /**< 缩进结果偏移量 */
  24. CGFloat edgeRetractAlpha; /**< 缩进后的透明度 */
  25. } MISEdgeRetractConfig;
  26. UIKIT_STATIC_INLINE MISEdgeRetractConfig MISEdgeOffsetConfigMake(CGPoint edgeRetractOffset, CGFloat edgeRetractAlpha) {
  27. MISEdgeRetractConfig config = {edgeRetractOffset, edgeRetractAlpha};
  28. return config;
  29. }
  30. @class MISFloatingBall;
  31. @protocol MISFloatingBallDelegate;
  32. typedef void(^MISFloatingBallClickHandler)(MISFloatingBall *floatingBall);
  33. @interface MISFloatingBall : UIView
  34. /**
  35. 靠边策略
  36. */
  37. @property (nonatomic, assign) MISFloatingBallEdgePolicy edgePolicy;
  38. /**
  39. 初始化只会在当前指定的 view 范围内生效的悬浮球
  40. 当 view 为 nil 的时候,和直接使用 initWithFrame 初始化效果一直,默认为全局生效的悬浮球
  41. @param frame 尺寸
  42. @param specifiedView 将要显示所在的view
  43. @return 悬浮球
  44. */
  45. - (instancetype)initWithFrame:(CGRect)frame inSpecifiedView:(nullable UIView *)specifiedView __deprecated_msg("Method deprecated. Use `initWithFrame:inSpecifiedView:effectiveEdgeInsets`");;
  46. /**
  47. 初始化只会在当前指定的 view 范围内生效的悬浮球
  48. 当 view 为 nil 的时候,和直接使用 initWithFrame 初始化效果一直,默认为全局生效的悬浮球
  49. @param frame 尺寸
  50. @param specifiedView 将要显示所在的view
  51. @param effectiveEdgeInsets 限制显示的范围,UIEdgeInsetsMake(50, 50, -50, -50)
  52. 则表示显示范围周围上下左右各缩小了 50 范围
  53. @return 生成的悬浮球实例
  54. */
  55. - (instancetype)initWithFrame:(CGRect)frame
  56. inSpecifiedView:(nullable UIView *)specifiedView
  57. effectiveEdgeInsets:(UIEdgeInsets)effectiveEdgeInsets;
  58. /**
  59. 悬浮球代理
  60. */
  61. @property (nonatomic, weak) id<MISFloatingBallDelegate> delegate;
  62. /**
  63. 显示
  64. */
  65. - (void)show;
  66. /**
  67. 隐藏
  68. */
  69. - (void)hide;
  70. - (void)visible __deprecated_msg("Method deprecated. Use `show`");
  71. - (void)disVisible __deprecated_msg("Method deprecated. Use `hide`");
  72. /**
  73. 是否自动靠边
  74. */
  75. @property (nonatomic, assign, getter=isAutoCloseEdge) BOOL autoCloseEdge;
  76. /**
  77. 当悬浮球靠近边缘的时候,自动像边缘缩进一段间距 (只有 autoCloseEdge 为YES时候才会生效)
  78. @param duration 缩进间隔
  79. @param edgeRetractConfigHander 缩进后参数的配置(如果为 NULL,则使用默认的配置)
  80. */
  81. - (void)autoEdgeRetractDuration:(NSTimeInterval)duration edgeRetractConfigHander:(nullable MISEdgeRetractConfig(^)())edgeRetractConfigHander;
  82. /**
  83. 设置ball内部的内容
  84. @param content 内容
  85. @param contentType 内容类型(存在三种文字,图片,和自定义传入视图)
  86. */
  87. - (void)setContent:(id)content contentType:(MISFloatingBallContentType)contentType;
  88. /**
  89. 点击 floatingBall 的 block 回调
  90. */
  91. @property (nonatomic, copy) MISFloatingBallClickHandler clickHandler;
  92. // 文字颜色
  93. @property (nonatomic, strong) UIColor *textTypeTextColor;
  94. @end
  95. @protocol MISFloatingBallDelegate <NSObject>
  96. @optional
  97. - (void)didClickFloatingBall:(MISFloatingBall *)floatingBall;
  98. @end
  99. @interface MISFloatingBall (Unavailable)
  100. - (instancetype)init NS_UNAVAILABLE;
  101. + (instancetype)new NS_UNAVAILABLE;
  102. @end
  103. NS_ASSUME_NONNULL_END