12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- //
- // LiveMoreDisplayView.m
- // TeacherDaya
- //
- // Created by 王智 on 2022/6/15.
- // Copyright © 2022 DayaMusic. All rights reserved.
- //
- #import "LiveMoreDisplayView.h"
- @interface LiveMoreDisplayView ()<UIGestureRecognizerDelegate>
- @property (weak, nonatomic) IBOutlet UIView *containerView;
- @property (nonatomic, copy) LiveMoreCallback callback;
- @end
- @implementation LiveMoreDisplayView
- - (void)awakeFromNib {
- [super awakeFromNib];
- [self setUpUI];
- [self addTapGesture];
- }
- - (void)setUpUI {
- if (@available(iOS 11.0, *)) {
- _containerView.layer.cornerRadius = 14;
- _containerView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner; // 左上圆角
- }
- else {
- UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:_containerView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(14, 14)];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = _containerView.bounds;
- maskLayer.path = path.CGPath;
- _containerView.layer.mask = maskLayer;
- }
- _containerView.layer.masksToBounds = YES;
- }
- - (void)addTapGesture {
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideView)];
- tap.delegate = self;
- [self addGestureRecognizer:tap];
- }
- - (void)hideView {
- [self removeFromSuperview];
- }
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
- if ([touch.view isDescendantOfView:self.containerView]) {
- return NO;
- }
- return YES;
- }
- + (instancetype)shareInstance {
- LiveMoreDisplayView *view = [[[NSBundle mainBundle] loadNibNamed:@"LiveMoreDisplayView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)operationQuitAction:(LiveMoreCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- }
- - (IBAction)pauseLive:(id)sender {
- if (self.callback) {
- self.callback(NO);
- }
- }
- - (IBAction)closeLive:(id)sender {
- if (self.callback) {
- self.callback(YES);
- }
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|