All Products
Search
Document Center

Menu component

Last Updated: May 25, 2021

The floating layer menu provides a menu containing icons and an option list.

When using it, you need to change the APNavPopview and APNavItemView in the original AntUI frameWork to AUFloatMenu and AUNavItemView.

Sample images

  • Floating layer with red dots

  • Floating layer with icon

  • Floating layer with text only

API description

  • AUFloatMenu.h
 
  1. //
  2. // AUFloatMenu.h
  3. // AntUI
  4. //
  5. #import <UIKit/UIKit.h>
  6. /* The notice of popview hiding. */
  7. static NSString * const APExtUIPopViewDissmissedNotification = @"APExtUIPopViewDissmissedNotification";
  8. @class AUNavItemView;
  9. /*!
  10. @class AUFloatMenu
  11. @abstract UIView
  12. @ Discussion floatViewMenu The floating layer.
  13. */
  14. @interface AUFloatMenu : UIView<UIGestureRecognizerDelegate>
  15. @property(nonatomic, assign) CGFloat marginToRight; // The right margin of a white popview, which is 10 by default.
  16. /**
  17. * Create a floating menu view.
  18. *
  19. * @param position The position where the floating menu is displayed on the screen.
  20. * @param items The array of displayed content, which is generally an APNavItemView object.
  21. *
  22. * @return The floating menu view.
  23. */
  24. +(AUFloatMenu *)showAtPostion:(CGPoint)position items:(NSArray<AUNavItemView *> *)items;
  25. /**
  26. * Create a floating menu view.
  27. *
  28. * @param position The position where the floating menu is displayed on the screen.
  29. * @param orignY The y-coordinate value of the floating menu on the screen.
  30. * @param items The array of displayed content, which is generally an APNavItemView object.
  31. *
  32. * @return The floating menu view.
  33. */
  34. +(AUFloatMenu *)showAtPostion:(CGPoint)position startOrignY:(CGFloat)orignY items:(NSArray<AUNavItemView *> *)items;
  35. /**
  36. * The interface method for hiding a floating menu.
  37. */
  38. -(void)dismiss;
  39. /**
  40. * After the menu is open, RPC is executed to load dynamically delivered menu items. After RPC is completed, the update() method is called to remove the original view and add a new view.
  41. */
  42. - (void)updateWithItems:(NSArray<AUNavItemView*> *)items;
  43. @end
  • AUNavItemView.h
 
  1. //
  2. // AUNavItemView.h
  3. // AntUI
  4. //
  5. #import <UIKit/UIKit.h>
  6. typedef NS_ENUM(NSInteger, AUCurrentTabType) {
  7. AUCurrentTabTypeHome = 0,
  8. AUCurrentTabTypeKouBei,
  9. AUCurrentTabTypeFriend,
  10. AUCurrentTabTypeWealth
  11. };
  12. /*!
  13. @class AUNavItemView
  14. @abstract UIView
  15. @ Discussion floatMenu The view of each column at the floating layer.
  16. */
  17. @interface AUNavItemView : UIView
  18. /**
  19. * title
  20. */
  21. @property(nonatomic,strong)NSString *itemTitle;
  22. @property(nonatomic,strong,readonly)UIFont *titleFont;
  23. /**
  24. * The normal state.
  25. */
  26. @property(nonatomic,strong)UIImage *nomarlStateIconImage;
  27. /*
  28. * IconFont Name: If iconFont needs to be set, the AUNavItemView.h but not AUFloatMenu.h API is invoked.
  29. */
  30. @property(nonatomic,strong)NSString *nomarlStateIconFontName;
  31. /**
  32. * If widgetId is set, badgeNumber does not need to be set.
  33. */
  34. @property(nonatomic,strong)NSString *badgeNumber;
  35. /**
  36. * widgetId
  37. */
  38. @property(nonatomic, copy) NSString *widgetId;
  39. /**
  40. * The required prompt text for VoiceOver. The default value is the value of itemTitle. If itemTitle is not set, you need to manually set this attribute to support VoiceOver.
  41. */
  42. @property(nonatomic,strong)NSString *voiceOverText;
  43. @property(nonatomic,assign)BOOL isNavigationItem;
  44. @property(nonatomic,assign,readonly)CGFloat touchEventMargin;
  45. @property(nonatomic,assign)AUCurrentTabType currentTabType;
  46. @property(nonatomic,assign,readonly)CGFloat marginBetweenIconTitle;
  47. @property(nonatomic,assign,readonly)CGFloat marginBetweenLeftIcon;
  48. @property(nonatomic,assign,readonly)CGFloat badgeViewWidth;
  49. /**
  50. * This method needs to be rewritten for a sub-class, and then the clicking event is processed.
  51. */
  52. - (void)onClicked;
  53. /**
  54. Return the size of the icon view.
  55. @return size
  56. */
  57. - (CGSize) iconViewSize;
  58. @end

Sample code

  • Example of a floating layer with red dots:
 
  1. //
  2. // APNavPopViewViewController.m
  3. // UIDemo
  4. //
  5. #import "APNavPopViewViewController.h"
  6. #import "AUUtils.h"
  7. #import "AUNavItemView.h"
  8. #import "AUFloatMenu.h"
  9. #import "AntUIShellObject.h"
  10. #import "AUIconView.h"
  11. @interface APNavPopViewViewController ()
  12. @end
  13. @implementation APNavPopViewViewController
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. self.view.backgroundColor = RGB(0xF5F5F9);
  17. self.navigationItem.title = @"带红点浮层";
  18. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"APCommonUI_ForDemo.bundle/more.png"] style:UIBarButtonItemStylePlain target:self action:@selector(onClick:)];
  19. self.navigationItem.rightBarButtonItem = rightItem;
  20. [[AURegisterManager shareInstance] registerAUObject:[[AntUIShellObject alloc] init]];
  21. }
  22. - (void)didReceiveMemoryWarning {
  23. [super didReceiveMemoryWarning];
  24. // Dispose of any resources that can be recreated.
  25. }
  26. - (void)onClick:(id)sender
  27. {
  28. NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:4];
  29. NSArray *items = @[@"添加朋友",@"发起群聊",@"扫一扫",@"收钱",@"帮助"];
  30. int i = 0;
  31. for (NSString *typeName in items) {
  32. AUNavItemView *item = [[AUNavItemView alloc]initWithFrame:CGRectMake(20, 0, 0, 40)];
  33. item.itemTitle = typeName;
  34. item.isNavigationItem = NO;
  35. // iconfont is supported.
  36. // item.nomarlStateIconFontName = kICONFONT_USER_ADD;
  37. if (i == 0 ) {
  38. item.badgeNumber = @"1";
  39. UIImage *image = [UIImage imageNamed:@"ap_add_friend.png"];
  40. item.nomarlStateIconImage = image;
  41. } else if(i == 1) {
  42. item.badgeNumber = @"10";
  43. UIImage *image = [UIImage imageNamed:@"ap_group_talk.png"];
  44. item.nomarlStateIconImage = image;
  45. } else if(i == 2) {
  46. item.badgeNumber = @"100";
  47. UIImage *image = [UIImage imageNamed:@"ap_scan.png"];
  48. item.nomarlStateIconImage = image;
  49. } else if(i == 3) {
  50. item.badgeNumber = @"5";
  51. UIImage *image = [UIImage imageNamed:@"ap_qrcode.png"];
  52. item.nomarlStateIconImage = image;
  53. } else if(i == 4) {
  54. UIImage *image = [UIImage imageNamed:@"ap_help.png"];
  55. item.nomarlStateIconImage = image;
  56. }
  57. i++;
  58. [array addObject:item];
  59. }
  60. [AUFloatMenu showAtPostion:CGPointMake(0, 0) startOrignY:70 items:array];
  61. }
  62. - (void)onBarButtonClick:(id)sender
  63. {
  64. }
  65. @end
  • Example of a floating layer with icons:
 
  1. //
  2. // APNavPopViewViewController.m
  3. // UIDemo
  4. //
  5. #import "APNavPopViewNoneRedViewController.h"
  6. #import "AUUtils.h"
  7. #import "AUNavItemView.h"
  8. #import "AUFloatMenu.h"
  9. #import "AntUIShellObject.h"
  10. #import "AUIconView.h"
  11. @interface APNavPopViewNoneRedViewController ()
  12. @end
  13. @implementation APNavPopViewNoneRedViewController
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. self.view.backgroundColor = RGB(0xF5F5F9);
  17. self.navigationItem.title = @"带图标浮层";
  18. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"APCommonUI_ForDemo.bundle/more.png"] style:UIBarButtonItemStylePlain target:self action:@selector(onClick:)];
  19. self.navigationItem.rightBarButtonItem = rightItem;
  20. [[AURegisterManager shareInstance] registerAUObject:[[AntUIShellObject alloc] init]];
  21. }
  22. - (void)didReceiveMemoryWarning {
  23. [super didReceiveMemoryWarning];
  24. // Dispose of any resources that can be recreated.
  25. }
  26. - (void)onClick:(id)sender
  27. {
  28. NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:4];
  29. NSArray *items = @[@"添加朋友",@"发起群聊",@"扫一扫",@"收钱",@"帮助"];
  30. int i = 0;
  31. for (NSString *typeName in items) {
  32. AUNavItemView *item = [[AUNavItemView alloc]initWithFrame:CGRectMake(20, 0, 0, 40)];
  33. item.itemTitle = typeName;
  34. item.isNavigationItem = NO;
  35. // iconfont is supported.
  36. // item.nomarlStateIconFontName = kICONFONT_USER_ADD;
  37. if (i == 0 ) {
  38. // item.badgeNumber = @"1";
  39. UIImage *image = [UIImage imageNamed:@"ap_add_friend.png"];
  40. item.nomarlStateIconImage = image;
  41. } else if(i == 1) {
  42. // item.badgeNumber = @"10";
  43. UIImage *image = [UIImage imageNamed:@"ap_group_talk.png"];
  44. item.nomarlStateIconImage = image;
  45. } else if(i == 2) {
  46. // item.badgeNumber = @"100";
  47. UIImage *image = [UIImage imageNamed:@"ap_scan.png"];
  48. item.nomarlStateIconImage = image;
  49. } else if(i == 3) {
  50. // item.badgeNumber = @"5";
  51. UIImage *image = [UIImage imageNamed:@"ap_qrcode.png"];
  52. item.nomarlStateIconImage = image;
  53. } else if(i == 4) {
  54. UIImage *image = [UIImage imageNamed:@"ap_help.png"];
  55. item.nomarlStateIconImage = image;
  56. }
  57. i++;
  58. [array addObject:item];
  59. }
  60. [AUFloatMenu showAtPostion:CGPointMake(0, 0) startOrignY:70 items:array];
  61. }
  62. - (void)onBarButtonClick:(id)sender
  63. {
  64. }
  65. @end
  • Example of a floating layer with text only:
 
  1. //
  2. // APNavPopViewViewController.m
  3. // UIDemo
  4. //
  5. #import "APNavPopViewOnlyViewController.h"
  6. #import "AUUtils.h"
  7. #import "AUNavItemView.h"
  8. #import "AUFloatMenu.h"
  9. #import "AntUIShellObject.h"
  10. #import "AUIconView.h"
  11. @interface APNavPopViewOnlyViewController ()
  12. @end
  13. @implementation APNavPopViewOnlyViewController
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. self.view.backgroundColor = RGB(0xF5F5F9);
  17. self.navigationItem.title = @"纯文字浮层";
  18. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"APCommonUI_ForDemo.bundle/more.png"] style:UIBarButtonItemStylePlain target:self action:@selector(onClick:)];
  19. self.navigationItem.rightBarButtonItem = rightItem;
  20. [[AURegisterManager shareInstance] registerAUObject:[[AntUIShellObject alloc] init]];
  21. }
  22. - (void)didReceiveMemoryWarning {
  23. [super didReceiveMemoryWarning];
  24. // Dispose of any resources that can be recreated.
  25. }
  26. - (void)onClick:(id)sender
  27. {
  28. NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:4];
  29. NSArray *items = @[@"添加朋友",@"发起群聊",@"扫一扫",@"收钱",@"帮助"];
  30. int i = 0;
  31. for (NSString *typeName in items) {
  32. AUNavItemView *item = [[AUNavItemView alloc]initWithFrame:CGRectMake(0, 0, 0, 40)];
  33. item.itemTitle = typeName;
  34. item.isNavigationItem = NO;
  35. // iconfont is supported.
  36. // item.nomarlStateIconFontName = kICONFONT_USER_ADD;
  37. // if (i == 0 ) {
  38. //// item.badgeNumber = @"1";
  39. // UIImage *image = [UIImage imageNamed:@"ap_add_friend.png"];
  40. // item.nomarlStateIconImage = image;
  41. // } else if(i == 1) {
  42. //// item.badgeNumber = @"10";
  43. // UIImage *image = [UIImage imageNamed:@"ap_group_talk.png"];
  44. // item.nomarlStateIconImage = image;
  45. // } else if(i == 2) {
  46. //// item.badgeNumber = @"100";
  47. // UIImage *image = [UIImage imageNamed:@"ap_scan.png"];
  48. // item.nomarlStateIconImage = image;
  49. // } else if(i == 3) {
  50. //// item.badgeNumber = @"5";
  51. // UIImage *image = [UIImage imageNamed:@"ap_qrcode.png"];
  52. // item.nomarlStateIconImage = image;
  53. // } else if(i == 4) {
  54. // UIImage *image = [UIImage imageNamed:@"ap_help.png"];
  55. // item.nomarlStateIconImage = image;
  56. // }
  57. i++;
  58. [array addObject:item];
  59. }
  60. [AUFloatMenu showAtPostion:CGPointMake(0, 0) startOrignY:70 items:array];
  61. }
  62. - (void)onBarButtonClick:(id)sender
  63. {
  64. }
  65. @end