KSNewsAlert.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // KSNewsAlert.m
  3. // StudentDaya
  4. //
  5. // Created by Kyle on 2020/2/26.
  6. // Copyright © 2020 DayaMusic. All rights reserved.
  7. //
  8. #import "KSNewsAlert.h"
  9. #import "UIView+Animation.h"
  10. @interface KSNewsAlert ()
  11. @property (weak, nonatomic) IBOutlet UIImageView *newsImage;
  12. @property (nonatomic, copy) NewsCallback callback;
  13. @property (nonatomic, strong) NSString *linkUrl;
  14. @end
  15. @implementation KSNewsAlert
  16. + (instancetype)shareInstance {
  17. KSNewsAlert *view = [[[NSBundle mainBundle] loadNibNamed:@"KSNewsAlert" owner:nil options:nil] firstObject];
  18. view.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight);
  19. return view;
  20. };
  21. - (void)evaluateWithMessage:(NSString *)imgUrl linkUrl:(NSString *)linkUrl callbackAction:(NewsCallback)callback {
  22. self.linkUrl = linkUrl;
  23. [self.newsImage sd_setImageWithURL:[NSURL URLWithString:[imgUrl getUrlEndcodeString]] placeholderImage:[UIImage new]];
  24. if (callback) {
  25. self.callback = callback;
  26. }
  27. }
  28. - (void)showAlert {
  29. [[UIApplication sharedApplication].keyWindow addSubview:self];
  30. [self setPopAnimation];
  31. }
  32. - (void)showAlertInView:(UIView *)displayView {
  33. [displayView addSubview:self];
  34. [self setPopAnimation];
  35. }
  36. - (void)hiddenAction {
  37. [self removeFromSuperview];
  38. }
  39. - (IBAction)sureAction:(id)sender {
  40. if (self.callback) {
  41. self.callback(YES, self.linkUrl);
  42. }
  43. [self hiddenAction];
  44. }
  45. - (IBAction)cancleAction:(id)sender {
  46. if (self.callback) {
  47. self.callback(NO, self.linkUrl);
  48. }
  49. [self hiddenAction];
  50. }
  51. /*
  52. // Only override drawRect: if you perform custom drawing.
  53. // An empty implementation adversely affects performance during animation.
  54. - (void)drawRect:(CGRect)rect {
  55. // Drawing code
  56. }
  57. */
  58. @end