MoveMegAlert.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // MoveMegAlert.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/4/30.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "MoveMegAlert.h"
  9. static UINib *ViewNib = nil;
  10. @interface MoveMegAlert()
  11. @end
  12. static MoveMegAlert *alert = nil;
  13. static dispatch_once_t onceToken;
  14. @implementation MoveMegAlert
  15. + (instancetype)share
  16. {
  17. dispatch_once(&onceToken, ^{
  18. if (ViewNib == nil) {
  19. ViewNib = [UINib nibWithNibName:@"MoveMegAlert" bundle:nil];
  20. }
  21. alert = [[ViewNib instantiateWithOwner:nil options:nil] lastObject];
  22. [alert setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  23. alert.backgroundColor = [UIColor clearColor];
  24. // [alert.disBtn addTarget:alert action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
  25. [alert.cancelBtn addTarget:alert action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
  26. [alert.doneBtn addTarget:alert action:@selector(doneAction) forControlEvents:UIControlEventTouchUpInside];
  27. });
  28. return alert;
  29. }
  30. - (void)doneAction
  31. {
  32. if (self.DoneBlock) {
  33. self.DoneBlock();
  34. }
  35. [self dismiss];
  36. }
  37. - (void)show
  38. {
  39. UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
  40. [window addSubview:self];
  41. [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
  42. } completion:^(BOOL finished) {
  43. }];
  44. }
  45. - (void)dismiss
  46. {
  47. WS(weakSelf);
  48. [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
  49. } completion:^(BOOL finished) {
  50. [weakSelf removeFromSuperview];
  51. }];
  52. }
  53. @end