ASHomeAlertWindow.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. ASHomeAlertWindow * _Nullable homeAlertW;
  10. @interface ASHomeAlertWindow ()
  11. @property (nonatomic, strong) ASHomeAlertViewController *vc;
  12. @end
  13. @implementation ASHomeAlertWindow
  14. + (void)clearWindow {
  15. for ( UIView *v in [homeAlertW.vc.view subviews]) {
  16. [v removeFromSuperview];
  17. }
  18. homeAlertW = nil;
  19. }
  20. - (instancetype)initWithFrame:(CGRect)frame {
  21. self = [super initWithFrame:frame];
  22. if (self) {
  23. [self createVc];
  24. }
  25. return self;
  26. }
  27. - (void)createVc {
  28. self.windowLevel = UIWindowLevelStatusBar + 3;
  29. self.vc = [[ASHomeAlertViewController alloc] init];
  30. self.vc.view.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.7];
  31. self.rootViewController = self.vc;
  32. [self makeKeyAndVisible];
  33. }
  34. + (void)showCustomVc:(UIView *)v position:(ASAlertPosition)postion {
  35. ASHomeAlertWindow *w = [[ASHomeAlertWindow alloc] initWithFrame: UIScreen.mainScreen.bounds];
  36. w.backgroundColor = UIColor.clearColor;
  37. [w.vc.view addSubview:v];
  38. homeAlertW = w;
  39. [v mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.leading.trailing.equalTo(w.vc.view);
  41. switch (postion) {
  42. case ASAlertPositionTop:
  43. make.top.equalTo(w.vc.view);
  44. break;
  45. case ASAlertPositionBottom:
  46. make.bottom.equalTo(w.vc.view);
  47. break;
  48. default:
  49. make.center.equalTo(w.vc.view);
  50. break;
  51. }
  52. }];
  53. }
  54. @end