KSPlatformDownloadAlert.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // KSPlatformDownloadAlert.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2024/9/14.
  6. //
  7. #import "KSPlatformDownloadAlert.h"
  8. @interface KSPlatformDownloadAlert ()
  9. @property (weak, nonatomic) IBOutlet UIView *containerView;
  10. @property (weak, nonatomic) IBOutlet UILabel *descLabel;
  11. @property (nonatomic, strong) UITapGestureRecognizer *gesture;
  12. @property (nonatomic, copy) DownloadSaveTipsCallback cancelCallback;
  13. @property (nonatomic, copy) DownloadSaveTipsCallback copyBlock;
  14. @property (nonatomic, copy) DownloadSaveTipsCallback sureCallback;
  15. @end
  16. @implementation KSPlatformDownloadAlert
  17. + (instancetype)shareInstance {
  18. KSPlatformDownloadAlert *view = [[[NSBundle mainBundle] loadNibNamed:@"KSPlatformDownloadAlert" owner:nil options:nil] firstObject];
  19. return view;
  20. }
  21. - (void)configWithDesc:(NSString *)desc {
  22. if ([NSString isEmptyString:desc]) {
  23. desc = @"";
  24. }
  25. self.descLabel.text = desc;
  26. }
  27. - (void)actionCallbackCancel:(DownloadSaveTipsCallback)cancel copyCallback:(DownloadSaveTipsCallback)copyBlock sure:(DownloadSaveTipsCallback)sure {
  28. if (cancel) {
  29. self.cancelCallback = cancel;
  30. }
  31. if (copyBlock) {
  32. self.copyBlock = copyBlock;
  33. }
  34. if (sure) {
  35. self.sureCallback = sure;
  36. }
  37. }
  38. - (void)showAlert {
  39. UIView *displayView = [NSObject getKeyWindow];
  40. [displayView addSubview:self];
  41. [self mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.right.top.bottom.mas_equalTo(displayView);
  43. }];
  44. }
  45. - (IBAction)copyActipn:(id)sender {
  46. if (self.copyBlock) {
  47. self.copyBlock();
  48. }
  49. }
  50. - (void)removeAlert {
  51. [self removeFromSuperview];
  52. }
  53. - (IBAction)cancelAction:(id)sender {
  54. [self removeAlert];
  55. if (self.cancelCallback) {
  56. self.cancelCallback();
  57. }
  58. }
  59. - (IBAction)sureAction:(id)sender {
  60. [self removeAlert];
  61. if (self.sureCallback) {
  62. self.sureCallback();
  63. }
  64. }
  65. /*
  66. // Only override drawRect: if you perform custom drawing.
  67. // An empty implementation adversely affects performance during animation.
  68. - (void)drawRect:(CGRect)rect {
  69. // Drawing code
  70. }
  71. */
  72. @end