个播房上划加载下一个房间完成
This commit is contained in:
@@ -7,11 +7,12 @@
|
||||
|
||||
#import "AnchorRoomScrollView.h"
|
||||
#import "XPMacro.h"
|
||||
#import "RoomInfoModel.h"
|
||||
|
||||
@interface AnchorRoomScrollView()<UIScrollViewDelegate, UIGestureRecognizerDelegate>
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray * lives;
|
||||
@property (nonatomic, strong) UIImageView *downImageView;
|
||||
@property (nonatomic, strong) NetImageView *downImageView;
|
||||
@property (nonatomic, assign) NSInteger currentIndex;
|
||||
|
||||
@property (nonatomic, assign) BOOL canScroll;
|
||||
@@ -33,42 +34,32 @@
|
||||
self = [super initWithFrame:frame];
|
||||
if(self)
|
||||
{
|
||||
self.contentSize = CGSizeMake(0, frame.size.height * 3);
|
||||
self.contentOffset = CGPointMake(0, frame.size.height);
|
||||
self.contentSize = CGSizeMake(0, frame.size.height * 2);
|
||||
self.pagingEnabled = YES;
|
||||
self.opaque = YES;
|
||||
self.backgroundColor = [UIColor yellowColor];
|
||||
self.showsHorizontalScrollIndicator = NO;
|
||||
self.showsVerticalScrollIndicator = NO;
|
||||
self.delegate = self;
|
||||
self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||||
self.tag = 1000;
|
||||
self.alwaysBounceVertical = NO;
|
||||
self.bounces = NO;
|
||||
self.delaysContentTouches = NO;
|
||||
// self.canCancelContentTouches = NO;
|
||||
self.scrollsToTop = NO;
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(roomMessageTabelViewStopScroll) name:@"roomMessageTabelViewStopScroll" object:nil];
|
||||
// image views
|
||||
// blur effect
|
||||
// UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
|
||||
// blur view
|
||||
// UIVisualEffectView *visualEffectViewUpper = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
|
||||
// UIVisualEffectView *visualEffectViewMiddle = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
|
||||
// UIVisualEffectView *visualEffectViewDown = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
|
||||
self.upperImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
|
||||
self.middleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, frame.size.height, frame.size.width, frame.size.height)];
|
||||
self.downImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, frame.size.height*2, frame.size.width, frame.size.height)];
|
||||
// add image views
|
||||
[self addSubview:self.upperImageView];
|
||||
|
||||
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];
|
||||
// visualEffectViewUpper.frame = self.upperImageView.frame;
|
||||
// [self addSubview:visualEffectViewUpper];
|
||||
// visualEffectViewMiddle.frame = self.middleImageView.frame;
|
||||
// [self addSubview:visualEffectViewMiddle];
|
||||
// visualEffectViewDown.frame = self.downImageView.frame;
|
||||
// [self addSubview:visualEffectViewDown];
|
||||
|
||||
}
|
||||
return self;
|
||||
@@ -78,128 +69,60 @@
|
||||
self.scrollEnabled = YES;
|
||||
}
|
||||
|
||||
- (void)updateForLives:(NSMutableArray *)livesArray withCurrentIndex:(NSInteger)index
|
||||
- (void)updateForAnchorRoomList:(NSMutableArray *)livesArray
|
||||
{
|
||||
if (livesArray.count && [livesArray firstObject]) {
|
||||
[self.lives removeAllObjects];
|
||||
[self.lives addObjectsFromArray:livesArray];
|
||||
self.currentIndex = index;
|
||||
|
||||
|
||||
[self prepareForImageView:self.upperImageView];
|
||||
[self prepareForImageView:self.middleImageView];
|
||||
[self prepareForImageView:self.downImageView];
|
||||
RoomInfoModel *roomInfo = self.lives[0];
|
||||
self.middleImageView.imageUrl = roomInfo.backPic;
|
||||
}
|
||||
if (livesArray.count > 1) {
|
||||
RoomInfoModel *roomInfo = self.lives[1];
|
||||
self.downImageView.imageUrl = roomInfo.backPic;
|
||||
}
|
||||
self.scrollEnabled = livesArray.count > 1;
|
||||
}
|
||||
|
||||
- (void) prepareForImageView: (UIImageView *)imageView {
|
||||
imageView.image = [UIImage imageNamed:@"room_background"];
|
||||
imageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
}
|
||||
|
||||
- (void)switchPlayer:(UIScrollView*)scrollView
|
||||
{
|
||||
CGFloat offset = scrollView.contentOffset.y;
|
||||
if (self.lives.count) {
|
||||
if (offset >= 2*self.frame.size.height)
|
||||
if (self.lives.count > 1) {
|
||||
if (offset >= self.frame.size.height)
|
||||
{
|
||||
// slides to the down player
|
||||
scrollView.contentOffset = CGPointMake(0, self.frame.size.height);
|
||||
scrollView.contentOffset = CGPointMake(0, 0);
|
||||
_currentIndex++;
|
||||
self.upperImageView.image = self.middleImageView.image;
|
||||
self.middleImageView.image = self.downImageView.image;
|
||||
if (_currentIndex == self.lives.count)
|
||||
{
|
||||
_currentIndex = 0;
|
||||
|
||||
}
|
||||
[self prepareForImageView:self.downImageView];
|
||||
if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollView:currentPlayerIndex:)]) {
|
||||
[self.anchorScrollDelegate anchorScrollView:self currentPlayerIndex:_currentIndex];
|
||||
if (self.lives.count > 1) {
|
||||
RoomInfoModel *roomInfo = self.lives[1];
|
||||
self.downImageView.imageUrl = roomInfo.backPic;
|
||||
}
|
||||
if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollViewScrollToNext:)]) {
|
||||
[self.anchorScrollDelegate anchorScrollViewScrollToNext:self];
|
||||
}
|
||||
}
|
||||
else if (offset <= 0)
|
||||
{
|
||||
// slides to the upper player
|
||||
scrollView.contentOffset = CGPointMake(0, self.frame.size.height);
|
||||
_currentIndex--;
|
||||
self.downImageView.image = self.middleImageView.image;
|
||||
self.middleImageView.image = self.upperImageView.image;
|
||||
if (_currentIndex == -1)
|
||||
{
|
||||
_currentIndex = self.lives.count-1;
|
||||
}
|
||||
[self prepareForImageView:self.upperImageView];
|
||||
if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollView:currentPlayerIndex:)]) {
|
||||
[self.anchorScrollDelegate anchorScrollView:self currentPlayerIndex:_currentIndex];
|
||||
}
|
||||
} else {
|
||||
// scrollView.contentOffset = CGPointMake(0, self.frame.size.height);
|
||||
}
|
||||
} else {
|
||||
scrollView.contentOffset = CGPointMake(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
||||
NSLog(@"anchorroomScrollView---%f", scrollView.contentOffset.y);
|
||||
if (scrollView.contentOffset.y < KScreenHeight) {
|
||||
scrollView.contentOffset = CGPointMake(0, KScreenHeight);
|
||||
scrollView.scrollEnabled = NO;
|
||||
return;
|
||||
} else {
|
||||
scrollView.scrollEnabled = YES;
|
||||
if (scrollView.contentOffset.y == KScreenHeight) {
|
||||
if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollVieEndScroll:)]) {
|
||||
[self.anchorScrollDelegate anchorScrollVieEndScroll:self];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (scrollView.contentOffset.y > KScreenHeight) {
|
||||
if (scrollView.contentOffset.y > 0) {
|
||||
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];
|
||||
// 手动拖拽开始
|
||||
// if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollVieStartScroll:)]) {
|
||||
// [self.anchorScrollDelegate anchorScrollVieStartScroll:self];
|
||||
// }
|
||||
}
|
||||
|
||||
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
|
||||
self.scrollEnabled = YES;
|
||||
}
|
||||
|
||||
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
|
||||
scrollView.scrollEnabled = YES;
|
||||
// if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollVieEndScroll:)]) {
|
||||
// [self.anchorScrollDelegate anchorScrollVieEndScroll:self];
|
||||
// }
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
||||
self.scrollEnabled = YES;
|
||||
}
|
||||
|
||||
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
||||
self.scrollEnabled = YES;
|
||||
}
|
||||
|
||||
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
|
||||
if (scrollView.contentOffset.y < KScreenHeight) {
|
||||
// scrollView.contentOffset = CGPointMake(0, KScreenHeight);
|
||||
// scrollView.scrollEnabled = NO;
|
||||
return;
|
||||
}
|
||||
// 手动拖拽开始
|
||||
// if (self.anchorScrollDelegate && [self.anchorScrollDelegate respondsToSelector:@selector(anchorScrollVieStartScroll:)]) {
|
||||
// [self.anchorScrollDelegate anchorScrollVieStartScroll:self];
|
||||
// }
|
||||
}
|
||||
|
||||
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
|
||||
NSLog(@"endDecelerating--%f", scrollView.contentOffset.y);
|
||||
self.scrollEnabled = YES;
|
||||
}
|
||||
|
||||
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
|
||||
|
Reference in New Issue
Block a user