CYLPlusButton.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // CYLPlusButton.h
  3. // CYLTabBarController
  4. //
  5. // v1.16.0 Created by 微博@iOS程序犭袁 ( http://weibo.com/luohanchenyilong/ ) on 10/20/15.
  6. // Copyright © 2018 https://github.com/ChenYilong . All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "CYLConstants.h"
  10. @class CYLPlusButton;
  11. @protocol CYLPlusButtonSubclassing
  12. @required
  13. + (id)plusButton;
  14. @optional
  15. /*!
  16. * 用来自定义加号按钮的位置,如果不实现默认居中。
  17. * @attention 以下两种情况下,必须实现该协议方法,否则 CYLTabBarController 会抛出 exception 来进行提示:
  18. 1. 添加了 PlusButton 且 TabBarItem 的个数是奇数。
  19. 2. 实现了 `+plusChildViewController`。
  20. * @return 用来自定义加号按钮在 TabBar 中的位置。
  21. *
  22. */
  23. + (NSUInteger)indexOfPlusButtonInTabBar;
  24. /*!
  25. * 该方法是为了调整 PlusButton 中心点Y轴方向的位置,建议在按钮超出了 tabbar 的边界时实现该方法。
  26. * @attention 如果不实现该方法,内部会自动进行比对,预设一个较为合适的位置,如果实现了该方法,预设的逻辑将失效。
  27. * @return 返回值是自定义按钮中心点Y轴方向的坐标除以 tabbar 的高度,
  28. 内部实现时,会使用该返回值来设置 PlusButton 的 centerY 坐标,公式如下:
  29. `PlusButtonCenterY = multiplierOfTabBarHeight * tabBarHeight + constantOfPlusButtonCenterYOffset;`
  30. 也就是说:如果 constantOfPlusButtonCenterYOffset 为0,同时 multiplierOfTabBarHeight 的值是0.5,表示 PlusButton 居中,小于0.5表示 PlusButton 偏上,大于0.5则表示偏下。
  31. *
  32. */
  33. + (CGFloat)multiplierOfTabBarHeight:(CGFloat)tabBarHeight;
  34. /*!
  35. * 见 `+multiplierOfTabBarHeight:` 注释:
  36. * `PlusButtonCenterY = multiplierOfTabBarHeight * tabBarHeight + constantOfPlusButtonCenterYOffset;`
  37. * 也就是说: constantOfPlusButtonCenterYOffset 大于0会向下偏移,小于0会向上偏移。
  38. * @attention 实现了该方法,但没有实现 `+multiplierOfTabBarHeight:` 方法,在这种情况下,会在预设逻辑的基础上进行偏移。
  39. */
  40. + (CGFloat)constantOfPlusButtonCenterYOffsetForTabBarHeight:(CGFloat)tabBarHeight;
  41. /*!
  42. * 实现该方法后,能让 PlusButton 的点击效果与跟点击其他 TabBar 按钮效果一样,跳转到该方法指定的 UIViewController 。
  43. * @attention 必须同时实现 `+indexOfPlusButtonInTabBar` 来指定 PlusButton 的位置。
  44. * @return 指定 PlusButton 点击后跳转的 UIViewController。
  45. *
  46. */
  47. + (UIViewController *)plusChildViewController;
  48. /*!
  49. *
  50. Asks the delegate whether the specified view controller should be made active.
  51. Return YES if the view controller’s tab should be selected or NO if the current tab should remain active.
  52. Returns YES true if the view controller’s tab should be selected or
  53. NO false if the current tab should remain active.
  54. */
  55. + (BOOL)shouldSelectPlusChildViewController;
  56. #pragma mark - Deprecated API
  57. + (CGFloat)multiplerInCenterY CYL_DEPRECATED("Deprecated in 1.6.0. Use `+multiplierOfTabBarHeight:` instead.");
  58. + (NSString *)tabBarContext;
  59. @end
  60. @class CYLTabBar;
  61. FOUNDATION_EXTERN UIButton<CYLPlusButtonSubclassing> *CYLExternPlusButton;
  62. FOUNDATION_EXTERN UIViewController *CYLPlusChildViewController;
  63. @interface CYLPlusButton : UIButton
  64. + (void)registerPlusButton;
  65. - (void)plusChildViewControllerButtonClicked:(UIButton<CYLPlusButtonSubclassing> *)sender;
  66. @end
  67. #pragma mark - Deprecated API
  68. @interface CYLPlusButton (CYLDeprecated)
  69. + (void)registerSubclass CYL_DEPRECATED("Deprecated in 1.6.0. Use `+[CYLPlusButton registerPlusButton]` instead.");
  70. @end