ASHomeAlertWindow.m 1.5 KB

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