1. 星速云首页
  2. 阿里云文档

阿里云移动开发平台mPaaS卡片菜单

在 iOS 中,beeviews:BEEPopMenuView 需要替换为 AUCardMenu.h。

效果图

  • 弹出菜单/多行组合样式

    阿里云移动开发平台mPaaS卡片菜单

  • 弹出菜单/按压效果

    阿里云移动开发平台mPaaS卡片菜单

  • 弹出菜单/双行

    阿里云移动开发平台mPaaS卡片菜单

  • 弹出菜单+选择按钮

    阿里云移动开发平台mPaaS卡片菜单

接口定义

  • AUCardMenu.h
  1. //
  2. // AUCardMenu.h
  3. // AntUI
  4. //
  5. @class AUMultiStyleCellView;
  6. @class AUWindow;
  7. /*!
  8. @class AUCardMenu
  9. @abstract AUWindow
  10. @discussion 带 蒙层 + 方向角 的弹出菜单
  11. */
  12. @interface AUCardMenu : AUWindow
  13. {
  14. }
  15. /**
  16. * 若需要响应点击事件,需要对 cellView 实现 AUMultiStyleCellDelegate 协议
  17. * 在自己的 viewcontroller 中赋值 popMenuView.cellView.delegate = self;
  18. */
  19. @property (nonatomic, strong) AUMultiStyleCellView *cellView;
  20. /**
  21. * 初始化方法(强烈推荐此方法)
  22. *
  23. * @param data 数组存放对象模型 CellDataModel
  24. * @param location 方向角的基准点
  25. * @param offset 方向角相对基准点的偏移量
  26. *
  27. * @return self
  28. */
  29. - (instancetype)initWithData:(NSArray *)data
  30. location:(CGPoint)location
  31. offset:(CGFloat)offset;
  32. /**
  33. * 展示弹出菜单
  34. *
  35. * @param superView PopMenuView的superView
  36. */
  37. - (void)showPopMenu:(UIView *)superView;
  38. // 隐藏弹出菜单,最好在 dealloc 方法里也调用
  39. - (void)hidePopMenu;
  40. // 注意:带动画方式的展示或消失必须成对使用,即:动画出现必须动画消失,非动画出现必须非动画消失
  41. // 带有动画方式的展示菜单
  42. - (void)showPopMenu:(UIView *)superView animation:(BOOL) isAnimation;
  43. // 带动画方式的消失菜单
  44. - (void)hidePopMenuWithAnimation:(BOOL)isAnimation;
  45. @end
  • AUCellDataModel.h
  1. //
  2. // AUCellDataModel.h
  3. // AntUI
  4. //
  5. #import <Foundation/Foundation.h>
  6. /*!
  7. @class AUMultiStyleCellView
  8. @abstract UIView
  9. @discussion menu中的子view
  10. */
  11. @interface AUCellDataModel : NSObject
  12. @property (nonatomic, strong) NSString *iconUrl;
  13. @property (nonatomic, strong) NSString *titleText;
  14. @property (nonatomic, strong) NSString *descText;
  15. @property (nonatomic, strong) NSString *checkMarkUrl; // 对勾
  16. @property (nonatomic, strong) NSString *indicatorUrl; // 右指示箭头
  17. @property (nonatomic, strong) NSArray *buttonsArray; // NSArray<NSString>
  18. @property (nonatomic, strong) NSDictionary *extendDic; // 给业务方使用的扩展字段
  19. @property (nonatomic, assign) BOOL selectedState; // 当前model选中状态,默认为 NO,即不选中
  20. @end
  • AUMultiStyleCellView.h
  1. //
  2. // AUMultiStyleCellView.h
  3. // AntUI
  4. //
  5. #import <UIKit/UIKit.h>
  6. #import "AUCellDataModel.h"
  7. @class AUMultiStyleCellView;
  8. @protocol AUMultiStyleCellDelegate <NSObject>
  9. @optional
  10. /**
  11. * 点击事件回调
  12. *
  13. * @param dataModel 点击的 view 对应的数据模型
  14. * @param indexPath 点击的 view 在 CellDataModel 中的下标(若 CellDataModel.buttonsArray == nil,则 row 默认取值为 -1)
  15. */
  16. - (void)DidClickCellView:(AUCellDataModel *)dataModel ForRowAtIndexpath:(NSIndexPath *)indexPath;
  17. - (void)DidClickCellButton:(AUCellDataModel *)dataModel ForRowAtIndexpath:(NSIndexPath *)indexPath;
  18. - (void)DidClickCellView:(AUCellDataModel *)dataModel ForRowAtIndexpath:(NSIndexPath *)indexPath cellView:(AUMultiStyleCellView *)cellView;
  19. @end
  20. /**
  21. * 融合多样式的cellview
  22. * 1. 图标 + 主标题
  23. * 2. 图标 + 主标题 + 位于主标题下方的副标题
  24. * 3. 图标 + 主标题 + 多行多列的带边框按钮控件
  25. */
  26. @interface AUMultiStyleCellView : UIView
  27. @property (nonatomic, weak) id<AUMultiStyleCellDelegate> delegate;
  28. @property (nonatomic, strong) NSArray *cellDataArray;
  29. // 如果 cellDataArray 为空等同于调用 initWithFrame 方法
  30. - (instancetype)initWithFrame:(CGRect)frame
  31. cellDataArray:(NSArray *)cellDataArray
  32. isUpward:(BOOL)isUpward;
  33. // 提供处理当前 cellView 选中与否的状态
  34. - (void)updateSelectedState;
  35. @end

代码示例

  1. //
  2. // cardMenuController.m
  3. // AntUI
  4. //
  5. #import "cardMenuController.h"
  6. #import "AUCardMenu.h"
  7. #import "AUCellDataModel.h"
  8. #import "AUMultiStyleCellView.h"
  9. @interface cardMenuController ()<AUMultiStyleCellDelegate>
  10. @property (nonatomic,strong) AUCardMenu * popMenuView;
  11. @end
  12. @implementation cardMenuController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. // Do any additional setup after loading the view.
  16. self.view.backgroundColor = RGB(0xF5F5F9);
  17. UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
  18. [button setFrame:CGRectMake(0, 100, self.view.width, 100)];
  19. [button setTitle:@"弹出菜单/多行组合样式" forState:UIControlStateNormal];
  20. [button setTitleColor:RGB(0x888888) forState:UIControlStateNormal];
  21. [button addTarget:self
  22. action:@selector(handleButton:)
  23. forControlEvents:UIControlEventTouchUpInside];
  24. [button.titleLabel setTextAlignment:NSTextAlignmentLeft];
  25. [button.titleLabel setFont:[UIFont systemFontOfSize:14]];
  26. [button setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
  27. [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  28. [self.view addSubview:button];
  29. UIButton * button2 = [UIButton buttonWithType:UIButtonTypeCustom];
  30. [button2 setFrame:CGRectMake(0, 220, self.view.width, 100)];
  31. [button2 setTitle:@"弹出菜单/按压效果" forState:UIControlStateNormal];
  32. [button2 addTarget:self
  33. action:@selector(handleButton2:)
  34. forControlEvents:UIControlEventTouchUpInside];
  35. [button2.titleLabel setTextAlignment:NSTextAlignmentLeft];
  36. [button2 setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
  37. [button2 setContentMode:UIViewContentModeLeft];
  38. [button2 setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  39. [button2 setTitleColor:RGB(0x888888) forState:UIControlStateNormal];
  40. [button2.titleLabel setFont:[UIFont systemFontOfSize:14]];
  41. [self.view addSubview:button2];
  42. UIButton * button3 = [UIButton buttonWithType:UIButtonTypeCustom];
  43. [button3 setFrame:CGRectMake(0, 320, self.view.width, 100)];
  44. [button3 setTitle:@"弹出菜单/双行" forState:UIControlStateNormal];
  45. [button3 addTarget:self
  46. action:@selector(handleButton3:)
  47. forControlEvents:UIControlEventTouchUpInside];
  48. [button3.titleLabel setTextAlignment:NSTextAlignmentLeft];
  49. [button3 setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
  50. [button3 setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  51. [button3.titleLabel setFont:[UIFont systemFontOfSize:14]];
  52. [button3 setTitleColor:RGB(0x888888) forState:UIControlStateNormal];
  53. [self.view addSubview:button3];
  54. UIButton * button4 = [UIButton buttonWithType:UIButtonTypeCustom];
  55. [button4 setFrame:CGRectMake(0, 420, self.view.width, 100)];
  56. [button4 setTitle:@"弹出菜单+选择按钮" forState:UIControlStateNormal];
  57. [button4 addTarget:self
  58. action:@selector(handleButton4:)
  59. forControlEvents:UIControlEventTouchUpInside];
  60. [button4.titleLabel setTextAlignment:NSTextAlignmentLeft];
  61. [button4 setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
  62. [button4 setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  63. [button4.titleLabel setFont:[UIFont systemFontOfSize:14]];
  64. [button4 setTitleColor:RGB(0x888888) forState:UIControlStateNormal];
  65. [self.view addSubview:button4];
  66. }
  67. - (void)handleButton4:(UIButton *)button
  68. {
  69. AUCellDataModel * model = [[AUCellDataModel alloc] init];
  70. model.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_dislike.png";
  71. model.titleText = @"我不感兴趣";
  72. model.buttonsArray = @[@"过时",@"看过了",@"质量差"];
  73. model.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  74. AUCardMenu *tmpView=[[AUCardMenu alloc]initWithData:@[model] location:CGPointMake(button.width - 20, button.centerY) offset:13];
  75. tmpView.cellView.delegate=self;
  76. [tmpView showPopMenu:button animation:YES];
  77. self.popMenuView=tmpView;
  78. }
  79. - (void)handleButton3:(UIButton *)button
  80. {
  81. AUCellDataModel * model = [[AUCellDataModel alloc] init];
  82. model.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_ignore.png";
  83. model.titleText = @"忽略";
  84. // model.buttonsArray = @[@"你好",@"口吃吗",@"我不饿",@"你好吗",@"我很好"];
  85. model.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  86. AUCellDataModel * model4 = [[AUCellDataModel alloc] init];
  87. model4.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_reject.png";
  88. model4.titleText = @"不再接受此类消息";
  89. model4.descText = @"减少此类消息的接收";
  90. model4.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  91. AUCardMenu *tmpView=[[AUCardMenu alloc]initWithData:@[model,model4] location:CGPointMake(button.width - 20, button.centerY) offset:13];
  92. tmpView.cellView.delegate=self;
  93. [tmpView showPopMenu:button animation:YES];
  94. self.popMenuView=tmpView;
  95. }
  96. - (void)handleButton2:(UIButton *)button
  97. {
  98. AUCellDataModel * model = [[AUCellDataModel alloc] init];
  99. model.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_ignore.png";
  100. model.titleText = @"忽略";
  101. // model.buttonsArray = @[@"你好",@"口吃吗",@"我不饿",@"你好吗",@"我很好"];
  102. model.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  103. AUCellDataModel * model2 = [[AUCellDataModel alloc] init];
  104. model2.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_dislike.png";
  105. model2.titleText = @"我不感兴趣";
  106. model2.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  107. model2.highlightState = YES;
  108. AUCellDataModel * model3 = [[AUCellDataModel alloc] init];
  109. model3.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_inform.png";
  110. model3.titleText = @"投诉";
  111. model3.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  112. AUCellDataModel * model4 = [[AUCellDataModel alloc] init];
  113. model4.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_reject.png";
  114. model4.titleText = @"不再接受此类消息";
  115. model4.descText = @"减少此类消息的接收";
  116. model4.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  117. AUCardMenu *tmpView=[[AUCardMenu alloc]initWithData:@[model,model2,model3,model4] location:CGPointMake(button.width - 20, button.centerY) offset:13];
  118. tmpView.cellView.delegate=self;
  119. [tmpView showPopMenu:button animation:YES];
  120. self.popMenuView=tmpView;
  121. }
  122. - (void)handleButton:(UIButton *)button
  123. {
  124. AUCellDataModel * model = [[AUCellDataModel alloc] init];
  125. model.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_ignore.png";
  126. model.titleText = @"忽略";
  127. // model.buttonsArray = @[@"你好",@"口吃吗",@"我不饿",@"你好吗",@"我很好"];
  128. model.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  129. AUCellDataModel * model2 = [[AUCellDataModel alloc] init];
  130. model2.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_dislike.png";
  131. model2.titleText = @"我不感兴趣";
  132. model2.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  133. AUCellDataModel * model3 = [[AUCellDataModel alloc] init];
  134. model3.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_inform.png";
  135. model3.titleText = @"投诉";
  136. model3.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  137. AUCardMenu *tmpView=[[AUCardMenu alloc]initWithData:@[model,model2,model3] location:CGPointMake(button.width - 20, button.centerY) offset:13];
  138. tmpView.cellView.delegate=self;
  139. [tmpView showPopMenu:button animation:YES];
  140. self.popMenuView=tmpView;
  141. }
  142. - (void)didReceiveMemoryWarning {
  143. [super didReceiveMemoryWarning];
  144. // Dispose of any resources that can be recreated.
  145. }
  146. - (void)hidePopMenu
  147. {
  148. if (self.popMenuView) {
  149. [self.popMenuView hidePopMenuWithAnimation:YES];
  150. self.popMenuView.cellView.delegate = nil;
  151. self.popMenuView = nil;
  152. }
  153. }
  154. #pragma mark --- AUMultiStyleCellDelegate
  155. /**
  156. * 点击事件回调
  157. *
  158. * @param dataModel 点击的 view 对应的数据模型
  159. * @param indexPath 点击的 view 在 CellDataModel 中的下标(若 CellDataModel.buttonsArray == nil,则 row 默认取值为 -1)
  160. */
  161. - (void)DidClickCellView:(AUCellDataModel *)dataModel ForRowAtIndexpath:(NSIndexPath *)indexPath
  162. {
  163. [self hidePopMenu];
  164. }
  165. - (void)DidClickCellButton:(AUCellDataModel *)dataModel ForRowAtIndexpath:(NSIndexPath *)indexPath
  166. {
  167. [self hidePopMenu];
  168. }
  169. - (void)DidClickCellView:(AUCellDataModel *)dataModel ForRowAtIndexpath:(NSIndexPath *)indexPath cellView:(AUMultiStyleCellView *)cellView
  170. {
  171. [self hidePopMenu];
  172. }
  173. - (void)dealloc
  174. {
  175. self.popMenuView = nil;
  176. }
  177. /*
  178. #pragma mark - Navigation
  179. // In a storyboard-based application, you will often want to do a little preparation before navigation
  180. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  181. // Get the new view controller using [segue destinationViewController].
  182. // Pass the selected object to the new view controller.
  183. }
  184. */
  185. @end

注明:本文为星速云原创版权所有,禁止转载,一经发现将追究版权责任!

发表评论

登录后才能评论
问答社区 QQ客服
微信客服
微信客服
分享本页
返回顶部