AccompanyAlertView.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // AccompanyAlertView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/4/11.
  6. //
  7. #import "AccompanyAlertView.h"
  8. #import "KSStarView.h"
  9. @interface AccompanyAlertView ()<UITextViewDelegate>
  10. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *viewLeft;
  11. @property (weak, nonatomic) IBOutlet KSStarView *starView;
  12. @property (nonatomic, copy) AccompanyAlertCallback callback;
  13. @end
  14. @implementation AccompanyAlertView
  15. - (void)awakeFromNib {
  16. [super awakeFromNib];
  17. self.inputView.delegate = self;
  18. self.starView.hidden = YES;
  19. self.starView.allowMark = YES;
  20. if (IS_IPAD) {
  21. self.viewLeft.constant = KPortraitWidth / 4;
  22. }
  23. }
  24. + (instancetype)shareInstance {
  25. AccompanyAlertView *view = [[[NSBundle mainBundle] loadNibNamed:@"AccompanyAlertView" owner:nil options:nil] firstObject];
  26. view.frame = CGRectMake(0, 0, kScreen_Width, kScreen_Height);
  27. return view;
  28. }
  29. - (void)showInView:(UIView *)displayView showStarView:(BOOL)showStarView {
  30. if (showStarView) {
  31. self.starView.hidden = NO;
  32. }
  33. [displayView addSubview:self];
  34. }
  35. - (void)sureCallback:(AccompanyAlertCallback)callback {
  36. if (callback) {
  37. self.callback = callback;
  38. }
  39. }
  40. - (IBAction)cancelAction:(id)sender {
  41. [self removeFromSuperview];
  42. }
  43. - (IBAction)sureAction:(id)sender {
  44. NSInteger starNum = self.starView.rate * 5;
  45. if (self.callback) {
  46. self.callback(self.inputView.text, starNum);
  47. }
  48. [self removeFromSuperview];
  49. }
  50. #pragma mark ---- text view delegate
  51. - (void)textViewDidBeginEditing:(UITextView *)textView {
  52. self.tipsLabel.hidden = YES;
  53. }
  54. - (void)textViewDidEndEditing:(UITextView *)textView {
  55. if ([NSString isEmptyString:textView.text]) {
  56. self.tipsLabel.hidden = NO;
  57. }
  58. }
  59. - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
  60. [self endEditing:YES];
  61. return YES;
  62. }
  63. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  64. [self endEditing:YES];
  65. }
  66. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  67. // 输入控制
  68. NSString *newString = [textView.text stringByReplacingCharactersInRange:range withString:text];
  69. if (newString.length > 200) {
  70. return NO;
  71. }
  72. return YES;
  73. }
  74. /*
  75. // Only override drawRect: if you perform custom drawing.
  76. // An empty implementation adversely affects performance during animation.
  77. - (void)drawRect:(CGRect)rect {
  78. // Drawing code
  79. }
  80. */
  81. @end