LiveMoreDisplayView.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // LiveMoreDisplayView.m
  3. // TeacherDaya
  4. //
  5. // Created by 王智 on 2022/6/15.
  6. // Copyright © 2022 DayaMusic. All rights reserved.
  7. //
  8. #import "LiveMoreDisplayView.h"
  9. @interface LiveMoreDisplayView ()<UIGestureRecognizerDelegate>
  10. @property (weak, nonatomic) IBOutlet UIView *containerView;
  11. @property (nonatomic, copy) LiveMoreCallback callback;
  12. @end
  13. @implementation LiveMoreDisplayView
  14. - (void)awakeFromNib {
  15. [super awakeFromNib];
  16. [self setUpUI];
  17. [self addTapGesture];
  18. }
  19. - (void)setUpUI {
  20. if (@available(iOS 11.0, *)) {
  21. _containerView.layer.cornerRadius = 14;
  22. _containerView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner; // 左上圆角
  23. }
  24. else {
  25. UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:_containerView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(14, 14)];
  26. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  27. maskLayer.frame = _containerView.bounds;
  28. maskLayer.path = path.CGPath;
  29. _containerView.layer.mask = maskLayer;
  30. }
  31. _containerView.layer.masksToBounds = YES;
  32. }
  33. - (void)addTapGesture {
  34. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideView)];
  35. tap.delegate = self;
  36. [self addGestureRecognizer:tap];
  37. }
  38. - (void)hideView {
  39. [self removeFromSuperview];
  40. }
  41. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
  42. if ([touch.view isDescendantOfView:self.containerView]) {
  43. return NO;
  44. }
  45. return YES;
  46. }
  47. + (instancetype)shareInstance {
  48. LiveMoreDisplayView *view = [[[NSBundle mainBundle] loadNibNamed:@"LiveMoreDisplayView" owner:nil options:nil] firstObject];
  49. return view;
  50. }
  51. - (void)operationQuitAction:(LiveMoreCallback)callback {
  52. if (callback) {
  53. self.callback = callback;
  54. }
  55. }
  56. - (IBAction)pauseLive:(id)sender {
  57. if (self.callback) {
  58. self.callback(NO);
  59. }
  60. }
  61. - (IBAction)closeLive:(id)sender {
  62. if (self.callback) {
  63. self.callback(YES);
  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