个播房可以向上滚动

This commit is contained in:
fengshuo
2022-08-10 21:39:39 +08:00
parent 7ea61f988d
commit 1fa07e3f27
7 changed files with 226 additions and 91 deletions

View File

@@ -54,6 +54,9 @@ NS_ASSUME_NONNULL_BEGIN
/// @param roomUid 房间的uid
- (void)getCycleAnchorRoomList:(NSString *)roomUid;
///获取当前房间是否有效
- (void)getCurrentRoomInfo:(NSString *)roomUid;
@end
NS_ASSUME_NONNULL_END

View File

@@ -216,4 +216,13 @@
} roomUid:roomUid];
}
- (void)getCurrentRoomInfo:(NSString *)roomUid {
[Api getRoomInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
RoomInfoModel * roomInfo = [RoomInfoModel modelWithDictionary:data.data];
[[self getView] getCurrentRoomInfo:roomInfo];
} fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getCurrentRoomInfo:nil];
}] uid:roomUid intoUid:@""];
}
@end

View File

@@ -25,7 +25,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)getRoomSuperAdminScuccess:(NSArray *)list;
///获取下一个个播房成功
- (void)getNextAnchorRoomSuccess:(RoomInfoModel *)roomInfo;
///获取当前房间的信息
- (void)getCurrentRoomInfo:(RoomInfoModel *_Nullable)roomInfo;
@end
NS_ASSUME_NONNULL_END

View File

@@ -7,11 +7,11 @@
#import <UIKit/UIKit.h>
#import "NetImageView.h"
@class AnchorRoomScrollView;
@protocol AnchorRoomScrollViewDelegate <NSObject>
///滚动到上一个时回调
- (void)anchorScrollViewScrollToPrevious:(AnchorRoomScrollView *)anchorScrollView;
///滚动到下一个时回调
- (void)anchorScrollViewScrollToNext:(AnchorRoomScrollView *)anchorScrollView;
///开始停止
@@ -24,7 +24,12 @@
@interface AnchorRoomScrollView : UIScrollView
@property (nonatomic, assign) id<AnchorRoomScrollViewDelegate> anchorScrollDelegate;
@property (nonatomic, strong) NetImageView *middleImageView;
@property (nonatomic, strong) UIView *middleImageView;
@property (nonatomic,assign) BOOL isCanScrollTop;
///是不是下一个
@property (nonatomic,assign) BOOL isScrollNext;
///是不是上一个
@property (nonatomic,assign) BOOL isScrollPrevious;
- (instancetype)initWithFrame:(CGRect)frame;

View File

@@ -9,20 +9,21 @@
#import "XPMacro.h"
#import "RoomInfoModel.h"
//SVGA
#import "SVGA.h"
#import "SVGAParserManager.h"
#import <ReactiveObjC/ReactiveObjC.h>
@interface AnchorRoomScrollView()<UIScrollViewDelegate, UIGestureRecognizerDelegate>
///
@property (nonatomic, strong) SVGAImageView *svgDisplayView;
@property (nonatomic, strong) SVGAImageView *middleDisplayView;
@property (nonatomic, strong) SVGAParserManager *parserManager;
@property (nonatomic, strong) NetImageView *downImageView;
@property (nonatomic, strong) SVGAImageView *topDisplayView;
@property (nonatomic, strong) SVGAImageView *downDisplayView;
@property (nonatomic, assign) BOOL animatePlay;
@end
@implementation AnchorRoomScrollView
@@ -31,105 +32,126 @@
{
self = [super initWithFrame:frame];
if(self)
{
self.contentSize = CGSizeMake(0, frame.size.height * 2);
{
self.pagingEnabled = YES;
self.showsHorizontalScrollIndicator = NO;
self.showsVerticalScrollIndicator = NO;
self.delegate = self;
self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
self.alwaysBounceVertical = NO;
self.bounces = NO;
self.delaysContentTouches = NO;
self.scrollsToTop = NO;
self.scrollsToTop = NO;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(roomMessageTabelViewStopScroll) name:@"roomMessageTabelViewStopScroll" object:nil];
NetImageConfig * config = [[NetImageConfig alloc] init];
config.placeHolder = [UIImage imageNamed:@"room_background"];
self.middleImageView = [[NetImageView alloc] initWithConfig:config];
self.middleImageView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
self.middleImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.middleImageView clipsToBounds];
self.downImageView = [[NetImageView alloc] initWithConfig:config];
self.downImageView.frame = CGRectMake(0, frame.size.height, frame.size.width, frame.size.height);
self.downImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.downImageView clipsToBounds];
[self addSubview:self.middleImageView];
[self addSubview:self.downImageView];
[self addSubview:self.svgDisplayView];
self.svgDisplayView.frame = CGRectMake(0, frame.size.height, frame.size.width, frame.size.height);
self.isCanScrollTop = NO;
[self addSubview:self.topDisplayView];
[self addSubview:self.middleDisplayView];
[self addSubview:self.downDisplayView];
}
return self;
}
- (void)startAnimate {
- (void)startAnimate:(SVGAImageView *)displayView {
self.animatePlay = YES;
@weakify(self);
NSString *bgString = [[NSBundle mainBundle] pathForResource:@"anchor_room_bg" ofType:@"svga"];
NSURL *bgUrl = [NSURL fileURLWithPath:bgString];
[self.parserManager loadSvgaWithURL:bgUrl completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
@strongify(self);
if (videoItem != nil) {
CGFloat width = videoItem.videoSize.width;
CGFloat height = videoItem.videoSize.height;
if (width > height) {
self.svgDisplayView.contentMode = UIViewContentModeScaleAspectFit;
displayView.contentMode = UIViewContentModeScaleAspectFit;
} else {//
CGFloat resizeH = KScreenWidth * height / width;//
if (resizeH > KScreenHeight) {//
self.svgDisplayView.contentMode = UIViewContentModeScaleAspectFill;
displayView.contentMode = UIViewContentModeScaleAspectFill;
} else {//
self.svgDisplayView.contentMode = UIViewContentModeScaleAspectFit;
displayView.contentMode = UIViewContentModeScaleAspectFit;
}
}
self.svgDisplayView.loops = INT_MAX;
self.svgDisplayView.clearsAfterStop = NO;
self.svgDisplayView.videoItem = videoItem;
[self.svgDisplayView startAnimation];
displayView.loops = INT_MAX;
displayView.clearsAfterStop = NO;
displayView.videoItem = videoItem;
[displayView startAnimation];
}
} failureBlock:^(NSError * _Nullable error) {
}];
}
- (void)stopAnimate {
[self.svgDisplayView stopAnimation];
[self.middleDisplayView stopAnimation];
[self.topDisplayView stopAnimation];
[self.downDisplayView stopAnimation];
self.animatePlay = NO;
NSLog(@"动画结束了");
}
- (void)roomMessageTabelViewStopScroll {
self.scrollEnabled = YES;
}
- (void)switchPlayer:(UIScrollView*)scrollView
{
CGFloat offset = scrollView.contentOffset.y;
if (offset >= self.frame.size.height)
{
if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollViewScrollToNext:)]) {
[self.anchorScrollDelegate anchorScrollViewScrollToNext:self];
}
[self stopAnimate];
}
- (void)switchPlayer:(UIScrollView*)scrollView {
CGFloat offset = scrollView.contentOffset.y;
if (offset >= self.frame.size.height * 2)
{
if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollViewScrollToNext:)]) {
[self.anchorScrollDelegate anchorScrollViewScrollToNext:self];
}
[self stopAnimate];
} else if (offset <= 0) {
if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollViewScrollToPrevious:)]) {
[self.anchorScrollDelegate anchorScrollViewScrollToPrevious:self];
}
[self stopAnimate];
}
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y > 0) {
NSLog(@"滚动的Y:%.2f", scrollView.contentOffset.y);
if (scrollView.contentOffset.y > KScreenHeight) {///
if (scrollView.contentOffset.y <= (KScreenHeight * 1.5)) {
return;
}
if (!self.animatePlay) {
[self startAnimate];
[self startAnimate:self.downDisplayView];
}
if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollVieEndScroll:)]) {
[self.anchorScrollDelegate anchorScrollVieStartScroll:self];
}
} else if (scrollView.contentOffset.y == 0) {
if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollVieEndScroll:)]) {
[self.anchorScrollDelegate anchorScrollVieEndScroll:self];
}
}
[self switchPlayer:scrollView];
} else {///
if (scrollView.contentOffset.y > (KScreenHeight * 0.5)) {
return;
}
if (!self.animatePlay) {
[self startAnimate:self.topDisplayView];
}
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (self.isCanScrollTop) {
if (scrollView.contentOffset.y >= KScreenHeight * 2) {
if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollViewScrollToNext:)]) {
[self.anchorScrollDelegate anchorScrollViewScrollToNext:self];
}
} else if(scrollView.contentOffset.y <= 0) {
if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollViewScrollToPrevious:)]) {
[self.anchorScrollDelegate anchorScrollViewScrollToPrevious:self];
}
}
} else {
if (scrollView.contentOffset.y >= KScreenHeight) {
if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollViewScrollToNext:)]) {
[self.anchorScrollDelegate anchorScrollViewScrollToNext:self];
}
}
}
[self stopAnimate];
NSLog(@"scrollViewDidEndDeceleratingY:%.2f", scrollView.contentOffset.y);
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
///666
if (otherGestureRecognizer.view.tag == 666) {
@@ -140,14 +162,53 @@
return YES;
}
- (SVGAImageView *)svgDisplayView {
if (_svgDisplayView == nil) {
_svgDisplayView = [[SVGAImageView alloc] init];
_svgDisplayView.contentMode = UIViewContentModeScaleToFill;
_svgDisplayView.userInteractionEnabled = NO;
_svgDisplayView.backgroundColor = [UIColor clearColor];
- (void)setIsCanScrollTop:(BOOL)isCanScrollTop {
_isCanScrollTop = isCanScrollTop;
CGRect frame = self.frame;
if (_isCanScrollTop) {
self.contentSize = CGSizeMake(0, frame.size.height * 3);
self.topDisplayView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
self.middleDisplayView.frame = CGRectMake(0, frame.size.height, frame.size.width, frame.size.height);
self.downDisplayView.frame = CGRectMake(0, frame.size.height * 2, frame.size.width, frame.size.height);
self.middleImageView = self.middleDisplayView;
} else {
self.contentSize = CGSizeMake(0, frame.size.height * 2);
self.topDisplayView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
self.middleDisplayView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
self.downDisplayView.frame = CGRectMake(0, frame.size.height, frame.size.width, frame.size.height);
self.middleImageView = self.middleDisplayView;
}
}
- (SVGAImageView *)middleDisplayView {
if (_middleDisplayView == nil) {
_middleDisplayView = [[SVGAImageView alloc] init];
_middleDisplayView.contentMode = UIViewContentModeScaleToFill;
_middleDisplayView.userInteractionEnabled = NO;
_middleDisplayView.backgroundColor = [UIColor clearColor];
}
return _svgDisplayView;
return _middleDisplayView;
}
- (SVGAImageView *)topDisplayView {
if (_topDisplayView == nil) {
_topDisplayView = [[SVGAImageView alloc] init];
_topDisplayView.contentMode = UIViewContentModeScaleToFill;
_topDisplayView.userInteractionEnabled = NO;
_topDisplayView.backgroundColor = [UIColor clearColor];
}
return _topDisplayView;
}
- (SVGAImageView *)downDisplayView {
if (_downDisplayView == nil) {
_downDisplayView = [[SVGAImageView alloc] init];
_downDisplayView.contentMode = UIViewContentModeScaleToFill;
_downDisplayView.userInteractionEnabled = NO;
_downDisplayView.backgroundColor = [UIColor clearColor];
}
return _downDisplayView;
}
- (SVGAParserManager *)parserManager {

View File

@@ -84,7 +84,7 @@
[XCHUDTool showErrorWithMessage:@"房间公屏已关闭"];
return;
}
[XPRoomSendTextView showTextView:self.superview delegate:self.delegate atUid:nil atNick:nil];
[XPRoomSendTextView showTextView:[UIApplication sharedApplication].delegate.window delegate:self.delegate atUid:nil atNick:nil];
}
break;

View File

@@ -111,6 +111,11 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出
///
@property (nonatomic, strong) AnchorRoomSrollTipView *anchorScrollTipView;
///
@property (nonatomic,strong) NSMutableArray<NSString *> *anchorRoomList;
///
@property (nonatomic,assign) BOOL anchorIndex;
@end
@implementation XPRoomViewController
@@ -193,7 +198,7 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出
}
- (void)viewDidLoad {
[super viewDidLoad];
[super viewDidLoad];
[self exitOldRoom];
[self initSubViews];
[self initSubViewConstraints];
@@ -308,8 +313,8 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出
make.right.equalTo(self.activityContainerView.mas_left).offset(-10);
}];
[self.menuContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.view);
make.bottom.mas_equalTo(-kSafeAreaBottomHeight- 8);
make.left.right.mas_equalTo(self.anchorScrollView.middleImageView);
make.bottom.mas_equalTo(self.anchorScrollView.middleImageView).offset(-kSafeAreaBottomHeight- 8);
make.height.mas_equalTo(40);
}];
[self.activityContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -775,9 +780,14 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出
///)
- (void)getNextAnchorRoomSuccess:(RoomInfoModel *)roomInfo {
self.anchorScrollView.contentOffset = CGPointMake(0, 0);
self.anchorScrollView.contentOffset = CGPointMake(0, KScreenHeight);
[self hideHUD];
if (roomInfo) { //
NSString * roomUid = [NSString stringWithFormat:@"%ld", roomInfo.uid];
if (![self.anchorRoomList containsObject:[NSString stringWithFormat:@"%ld", roomInfo.uid]]) {
[self.anchorRoomList addObject:roomUid];
}
self.anchorIndex = self.anchorRoomList.count -1;
//1退
self.isRequestSuperAdmin = NO;
[self exitOldRoom];
@@ -807,6 +817,43 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出
} else {
[self showErrorToast:@"已经到底啦~自动为您返回当前房间"];
}
self.anchorScrollView.isScrollNext = NO;
}
- (void)getCurrentRoomInfo:(RoomInfoModel *)roomInfo {
[self hideHUD];
self.anchorScrollView.contentOffset = CGPointMake(0, KScreenHeight);
if (roomInfo && roomInfo.valid) {
//1退
self.isRequestSuperAdmin = NO;
[self exitOldRoom];
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[XPRoomMiniManager shareManager] resetLocalMessage];
[[RtcManager instance] exitRoom];
[self.presenter reportUserOutRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.uid]];
//2
[self.backContainerView removeFromSuperview];
[self.stageView removeFromSuperview];
[self.messageContainerView removeFromSuperview];
[self.activityContainerView removeFromSuperview];
[self.roomHeaderView removeFromSuperview];
[self.functionView removeFromSuperview];
self.functionView = nil;
self.messageContainerView = nil;
self.stageView = nil;
[self.menuContainerView removeFromSuperview];
self.menuContainerView = nil;
//3
self.roomUid = [NSString stringWithFormat:@"%zd", roomInfo.uid];
[self.presenter initEnterRoom:self.roomUid user:[AccountInfoStorage instance].getUid];
///
[self.presenter getNormalGiftList:self.roomUid];
///
[self.presenter getRoomSuperAdmin:self.roomUid];
} else {
[self showErrorToast:@"已经到顶啦~自动为您返回当前房间"];
}
}
///
@@ -825,7 +872,7 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出
} else {
self.roomInfo.datingState = self.roomInfo.roomModeType == RoomModeType_Open_Blind ? RoomDatingStateChangeType_Open : RoomDatingStateChangeType_Normal;
if (!self.anchorScrollView.superview) {
[self.view insertSubview:self.anchorScrollView belowSubview:self.menuContainerView];
[self.view addSubview:self.anchorScrollView];
}
[self.backContainerView removeFromSuperview];
[self.stageView removeFromSuperview];
@@ -833,6 +880,7 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出
[self.activityContainerView removeFromSuperview];
[self.roomHeaderView removeFromSuperview];
[self.functionView removeFromSuperview];
[self.menuContainerView removeFromSuperview];
[self.anchorScrollView addSubview:self.backContainerView];
[self.anchorScrollView addSubview:self.stageView];
@@ -840,9 +888,8 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出
[self.anchorScrollView addSubview:self.activityContainerView];
[self.anchorScrollView addSubview:self.roomHeaderView];
[self.anchorScrollView addSubview:self.functionView];
if (!self.menuContainerView.superview) {
[self.view addSubview:self.menuContainerView];
}
[self.anchorScrollView addSubview:self.menuContainerView];
[self updateViewConstraintsOnAnchorRoom];
[self changeStageViewOnAnchorRoom];
@@ -1376,21 +1423,21 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出
[self.presenter getCycleAnchorRoomList:[NSString stringWithFormat:@"%ld", self.roomInfo.uid]];
}
///
- (void)anchorScrollVieStartScroll:(AnchorRoomScrollView *)anchorScrollView {
if (self.menuContainerView.alpha == 0) {
return;
}
[UIView animateWithDuration:0.2 animations:^{
self.menuContainerView.alpha = 0;
}];
}
///
- (void)anchorScrollVieEndScroll:(AnchorRoomScrollView *)anchorScrollView {
[UIView animateWithDuration:0.2 animations:^{
self.menuContainerView.alpha = 1;
}];
- (void)anchorScrollViewScrollToPrevious:(AnchorRoomScrollView *)anchorScrollView {
if (!self || self.anchorRoomList.count <= 0) {
return;
}
[self.view endEditing:YES];
[self showAnchorLoading];
if (self.anchorIndex < self.anchorRoomList.count) {
NSString * roomUid = [self.anchorRoomList objectAtIndex:self.anchorIndex];
[self.presenter getCurrentRoomInfo:roomUid];
self.anchorIndex --;
}else {
[self showErrorToast:@"已经到顶啦~自动为您返回当前房间"];
self.anchorScrollView.contentOffset = CGPointMake(0, KScreenHeight);
}
}
#pragma mark - XPRoomSettingInputViewDelegate
@@ -1536,6 +1583,9 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出
if (!_anchorScrollView) {
_anchorScrollView = [[AnchorRoomScrollView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
_anchorScrollView.anchorScrollDelegate = self;
if (@available(iOS 11.0, *)) {
_anchorScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}
return _anchorScrollView;
}
@@ -1547,5 +1597,11 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出
return _anchorScrollTipView;
}
- (NSMutableArray<NSString *> *)anchorRoomList {
if (!_anchorRoomList) {
_anchorRoomList = [NSMutableArray array];
}
return _anchorRoomList;
}
@end