HFAlert.m 1.6 KB

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