| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- //
- // MOLiveSmallView.m
- // MiMoLive
- //
- // Created by SuperC on 2024/4/15.
- //
- #import "MOLiveSmallView.h"
- #import "MOForbidScreenShotView.h"
- static MOLiveSmallView *_sharedSingleton = nil;
- static dispatch_once_t onceToken;
- @interface MOLiveSmallView ()
- @property (nonatomic, strong) UIView *localView;
- @property (nonatomic, strong) BigBtn *closeBtn;
- @end
- @implementation MOLiveSmallView
- + (instancetype)sharedSingleton
- {
- static dispatch_once_t onceTokenK;
- dispatch_once(&onceTokenK, ^
- {
- // 要使用self来调用
-
- _sharedSingleton = [[self alloc] init];
- });
- return _sharedSingleton;
- }
- - (instancetype)init{
- self = [super init];
- if (self)
- {
- [self setupUI];
- }
-
- return self;
- }
- - (void)setupUI{
- UIView *superView = self;
- if (@available(iOS 13.2, *)) {
- UIView *tempView = [MOForbidScreenShotView creactWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
- tempView.backgroundColor = [UIColor clearColor];
- [self addSubview:tempView];
- [tempView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- }];
-
- superView = tempView;
- }
-
- [superView addSubview:self.localView];
- [self.localView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- }];
-
- [self addSubview:self.closeBtn];
- [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(10.0);
- make.right.equalTo(self).offset(-10.0);
- make.width.height.equalTo(@15.0);
- }];
- }
- - (void)setLiveModel:(MOLiveDetail *)liveModel{
- _liveModel = liveModel;
-
- WEAKSELF
- NSInteger agoraId = GetAgoraId;
- if(self.isCreatLive){
- [[MOShowAgoraKitManager shareManager] setupLocalVideoWithUid:agoraId AndCanvasView:self.localView];
- }
- else{
- [[MOShowAgoraKitManager shareManager] setupRemoteVideoWidhChannelId:liveModel.currentRoom.id UId:liveModel.currentRoom.anchorUser.agoraId CanvasView:self.localView];
- }
- }
- - (void)toShowTheLivingRoomWith:(MOShowLiveVC *)vc{
- self.showVC = vc;
-
- self.isSmallShow = YES;
-
- UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
- [keyWindow addSubview:self];
-
- CGFloat normalWidth = SCREENWIDTH;
- CGFloat normalHeight = SCREENHEIGHT;
- CGFloat newWidth = normalWidth / 4.0;
- CGFloat newHeight = normalHeight / 4.0;
- CGFloat x = normalWidth - newWidth - 10.0;
- CGFloat y = normalHeight - newHeight - 80.0;
-
- self.frame = CGRectMake(x, y, newWidth, newHeight);
- }
- #pragma mark ----- touchDelegate
- - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- self.center = [touches.anyObject locationInView:self.superview];
- }
- - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- [self endTouch:[touches.anyObject locationInView:self.superview]];
- }
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- [self endTouch:[touches.anyObject locationInView:self.superview]];
- }
- //吸附功能
- - (void)endTouch:(CGPoint)point
- {
- CGRect frame = self.frame;
- CGFloat width;
- CGFloat height;
-
- width = self.superview.height;
- height = self.superview.width;
-
- if (point.x > width / 2)
- {
- frame.origin.x = width - frame.size.width - 10.0;
- }
- else
- {
- frame.origin.x = 10.0;
- }
-
- if (frame.origin.y > height - 64 - frame.size.height)
- {
- frame.origin.y = height - 64 - frame.size.height;
- }
- else if (frame.origin.y < (self.superview.y + 10.0))
- {
- frame.origin.y = self.superview.y + 10.0;
- }
- [UIView animateWithDuration:0.3 animations:^
- {
- self.frame = frame;
- }];
- }
- #pragma mark - Lazy
- - (UIView *)localView{
- if(!_localView){
- _localView = [[UIView alloc] init];
- }
- return _localView;
- }
- - (BigBtn *)closeBtn{
- if (!_closeBtn)
- {
- _closeBtn = [BigBtn buttonWithType:UIButtonTypeCustom];
- _closeBtn.backgroundColor = [UIColor clearColor];
- [_closeBtn setImage:[UIImage imageNamed:@"icon_live_close"] forState:UIControlStateNormal];
- [_closeBtn addTarget:self action:@selector(closeWishBtnClick) forControlEvents:UIControlEventTouchUpInside];
- }
- return _closeBtn;
- }
- - (void)closeWishBtnClick{
- self.isSmallShow = NO;
-
- //判断视图中是否有直播间VC, 如果在外部则直接执行退出直播间操作, 如果有则隐藏小直播窗口
- }
- @end
|