ASHomeAlertWindow.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // ASHomeAlertWindow.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/16.
  6. //
  7. #import "ASHomeAlertWindow.h"
  8. #import "ASHomeAlertViewController.h"
  9. #import "ASDefualtAlertV.h"
  10. ASHomeAlertWindow * _Nullable homeAlertW;
  11. @interface ASHomeAlertWindow ()
  12. @property (nonatomic, strong) ASHomeAlertViewController *vc;
  13. @end
  14. @implementation ASHomeAlertWindow
  15. + (void)clearWindow {
  16. for ( UIView *v in [homeAlertW.vc.view subviews]) {
  17. [v removeFromSuperview];
  18. }
  19. homeAlertW = nil;
  20. }
  21. - (instancetype)initWithFrame:(CGRect)frame {
  22. self = [super initWithFrame:frame];
  23. if (self) {
  24. [self createVc];
  25. }
  26. return self;
  27. }
  28. - (void)createVc {
  29. self.windowLevel = UIWindowLevelStatusBar + 3;
  30. self.vc = [[ASHomeAlertViewController alloc] init];
  31. self.vc.view.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.7];
  32. self.rootViewController = self.vc;
  33. [self makeKeyAndVisible];
  34. }
  35. + (void)alertMsg:(NSString *)message {
  36. ASDefualtAlertV *v = [[ASDefualtAlertV alloc] initWithFrame:CGRectZero];
  37. [v setMsg:message];
  38. [v setViewStyle:ASAlertWidthStyleLittle];
  39. [ASHomeAlertWindow showCustomVc:v position:ASAlertPositionCenter];
  40. }
  41. + (void)showCustomVc:(UIView *)v position:(ASAlertPosition)postion {
  42. ASHomeAlertWindow *w = [[ASHomeAlertWindow alloc] initWithFrame: UIScreen.mainScreen.bounds];
  43. w.backgroundColor = UIColor.clearColor;
  44. [w.vc.view addSubview:v];
  45. homeAlertW = w;
  46. [v mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.leading.trailing.equalTo(w.vc.view);
  48. switch (postion) {
  49. case ASAlertPositionTop:
  50. make.top.equalTo(w.vc.view);
  51. break;
  52. case ASAlertPositionBottom:
  53. make.bottom.equalTo(w.vc.view);
  54. break;
  55. default:
  56. make.center.equalTo(w.vc.view);
  57. break;
  58. }
  59. }];
  60. }
  61. @end