HEMenu.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // HEMenuC.m
  3. // YHMenu
  4. //
  5. // Created by Boris on 2018/5/10.
  6. // Copyright © 2018年 Boris. All rights reserved.
  7. //
  8. #import "HEMenu.h"
  9. #import "MenuView.h"
  10. @interface HEMenu ()
  11. @property (nonatomic, strong) MenuView *menuView;
  12. @end
  13. @implementation HEMenu
  14. + (HEMenu *) shareManager {
  15. static HEMenu *menu = nil;
  16. static dispatch_once_t onceToken;
  17. dispatch_once(&onceToken, ^{
  18. menu = [[HEMenu alloc]init];
  19. });
  20. return menu;
  21. }
  22. - (void) showPopMenuSelecteWithFrameWidth:(CGFloat)width
  23. height:(CGFloat)height
  24. point:(CGPoint)point
  25. item:(NSArray *)item
  26. imgSource:(NSArray *)imgSource
  27. action:(void (^)(NSInteger index))action{
  28. __weak __typeof(&*self)weakSelf = self;
  29. if (self.menuView != nil) {
  30. [weakSelf hideMenu];
  31. }
  32. UIWindow * window = [[[UIApplication sharedApplication] windows] firstObject];
  33. self.menuView = [[MenuView alloc]initWithFrame:window.bounds
  34. menuWidth:width height:height point:point items:item imgSource:imgSource action:^(NSInteger index) {
  35. action(index);
  36. [weakSelf hideMenu];
  37. }];
  38. _menuView.touchBlock = ^{
  39. [weakSelf hideMenu];
  40. };
  41. self.menuView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.1];
  42. [window addSubview:self.menuView];
  43. }
  44. - (void) hideMenu {
  45. [self.menuView removeFromSuperview];
  46. self.menuView = nil;
  47. }
  48. @end