KSAudioSaveAlert.m 2.1 KB

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