Commit 859a366c cgx

优化轮播图自动无限循环播放

1 个父辈 3beeb052
......@@ -2276,7 +2276,7 @@
CODE_SIGN_ENTITLEMENTS = DreamSleep/Basement/DSConfig/DreamSleepDebug.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 4NDZ6UX8PW;
ENABLE_BITCODE = NO;
......@@ -2352,7 +2352,7 @@
CODE_SIGN_ENTITLEMENTS = DreamSleep/DreamSleep.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = 4NDZ6UX8PW;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
......@@ -2488,7 +2488,7 @@
CODE_SIGN_ENTITLEMENTS = DreamSleep/Basement/DSConfig/DreamSleepBeta.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 4NDZ6UX8PW;
ENABLE_BITCODE = NO;
......
......@@ -79,6 +79,24 @@
// 自动登录请求(调用时机)
[UserRequestModel autoLoginRequestWithCompletion:^(UserRequestModel * _Nonnull requestModel) {}];
}
[self.homeTV.headerView controllerWillAppear];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.homeTV.headerView controllerWillDisAppear];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[[NoisePlayerManager sharedNoisePlayerManager] pauseAll];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:NeedUpdateHomePage object:nil];
}
#pragma mark - 先放大,再缩小
......@@ -100,16 +118,6 @@
[view.layer addAnimation:animation forKey:nil];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[[NoisePlayerManager sharedNoisePlayerManager] pauseAll];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:NeedUpdateHomePage object:nil];
}
- (void)needUpdate {
[self.homeTV.mj_header beginRefreshing];
}
......
......@@ -6,12 +6,14 @@
//
#import <UIKit/UIKit.h>
#import "HomeHeaderView.h"
#import "SafeSleepModel.h"
NS_ASSUME_NONNULL_BEGIN
/// APP首页自定义视图
@interface DSHomeView : UITableView
@property (nonatomic, strong) HomeHeaderView *headerView;
/// 刷新banner
/// @param bannerListData bannerListData
......
......@@ -6,12 +6,10 @@
//
#import "DSHomeView.h"
#import "HomeHeaderView.h"
#import "CourseMusicCell.h"
#import "GoodSleepSoundCell.h"
@interface DSHomeView () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) HomeHeaderView *headerView;
@property (nonatomic, strong) NSArray *courseMusicArr;
/// 类型数据
@property (nonatomic, strong) NSArray *typeArr;
......@@ -27,7 +25,6 @@
self.showsVerticalScrollIndicator = NO;
self.delegate = self;
self.dataSource = self;
self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
[self registerClass:[CourseMusicCell class] forCellReuseIdentifier:NSStringFromClass([CourseMusicCell class])];
[self registerClass:[GoodSleepSoundCell class] forCellReuseIdentifier:NSStringFromClass([GoodSleepSoundCell class])];
self.tableHeaderView = self.headerView;
......
......@@ -16,6 +16,9 @@ NS_ASSUME_NONNULL_BEGIN
/// @param listData listData
- (void)updateBannerWithListData:(NSArray *)listData;
- (void)controllerWillAppear;
- (void)controllerWillDisAppear;
@end
NS_ASSUME_NONNULL_END
......@@ -52,6 +52,14 @@
[self.barnnerView freshCarousel];
}
- (void)controllerWillAppear {
[self.barnnerView controllerWillAppear];
}
- (void)controllerWillDisAppear {
[self.barnnerView controllerWillDisAppear];
}
#pragma mark - CWCarouselDatasource
- (NSInteger)numbersForCarousel {
return self.bannerDatas.count;
......
......@@ -36,6 +36,8 @@
if (cellIndex == 0) { // 舒眠课程
[self addSubview:self.courseIcon];
[self addSubview:self.courseLab];
self.courseIcon.hidden = NO;
self.courseLab.hidden = NO;
self.courseLab.text = [NSString stringWithFormat:@"%d", model.count];
[self.courseLab sizeToFit];
......@@ -48,6 +50,9 @@
make.left.equalTo(self.courseIcon.mas_right).offset(6);
make.centerY.equalTo(self.courseIcon);
}];
} else {
if (_courseIcon) { _courseIcon.hidden = YES; }
if (_courseLab) { _courseLab.hidden = YES; }
}
CGFloat width = 128;
......
......@@ -122,5 +122,7 @@ extern char** gArgv;
1、默认情况关闭手机静音按钮,进入Unity游戏后播放音频没有声音,需要到Unity工程-UnityAppController.mm修改源代码;
2、首次启动Unity游戏,默认会加载主APP启动页面,需要到Unity工程-UnityAppController+ViewHandling.mm修改源代码;
3、Unity工程不支持bitcode,需要关闭;
4、Unity工程有变化时需要手动编译生成新的UnityFramework.framework动态库,然后导入到该目录下:
$(PROJECT_DIR)/unity_build_framework(后续通过脚本优化?)
*/
@end
......@@ -160,7 +160,7 @@
#pragma mark - 授权失败的回调
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error API_AVAILABLE(ios(13.0)) {
NSString *errorMsg = nil;
NSString *errorMsg = @"";
switch (error.code) {
case ASAuthorizationErrorCanceled:
errorMsg = @"用户取消了授权请求";
......@@ -183,7 +183,7 @@
}
DSLog(@"controller requests:%@, errorMsg:%@", controller.authorizationRequests, errorMsg);
[DataStatisticsUtil event:Apple_Login attributes:@{@"name":@"苹果登录授权失败"}];
[DataStatisticsUtil event:Apple_Login attributes:@{@"name":errorMsg}];
}
#pragma mark - ASAuthorizationControllerPresentationContextProviding
......
......@@ -149,18 +149,12 @@
*/
- (void)controllerWillDisAppear;
/// 滚动到指定下标
/// @param index 指定下标
/// @param animation 是否开启滚动动画
- (void)scrollTo:(NSInteger)index animation:(BOOL)animation;
@end
@interface CWCarouselCollectionView: UICollectionView<UIGestureRecognizerDelegate>
@end
......
......@@ -9,13 +9,12 @@
#import "CWCarousel.h"
@interface CWCarouselCollectionView()
@property (nonatomic, copy) void (^ _Nullable tapCallback) (void);
@property (nonatomic, copy) void (^ _Nullable tapCallback) (void);
@end
@implementation CWCarouselCollectionView
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout {
if(self = [super initWithFrame:frame collectionViewLayout:layout]) {
if (self = [super initWithFrame:frame collectionViewLayout:layout]) {
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
[self addGestureRecognizer:tap];
tap.delegate = self;
......@@ -31,7 +30,6 @@
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] == NO) {
return YES;
}
......@@ -39,23 +37,20 @@
if ([[touch view] isKindOfClass:[UICollectionView class]]) {
return YES;
}
return NO;
}
- (void)dealloc {
NSLog(@"[CWCarouselCollectionView dealloc]");
DSLog(@"[CWCarouselCollectionView dealloc]");
}
@end
@interface CWTempleteCell: UICollectionViewCell
@end
@implementation CWTempleteCell
@end
@interface MyProxy : NSProxy
@property (nonatomic, weak) id _Nullable target;
- (instancetype)init:(id)target;
......@@ -77,43 +72,38 @@
@end
@interface CWCarousel ()<UICollectionViewDelegate, UICollectionViewDataSource> {
}
/// collectionView
@property (nonatomic, strong) CWCarouselCollectionView *carouselView;
/// 轮播总数
@property (nonatomic, assign) NSInteger numbers;
@property (nonatomic, assign) NSInteger numbers;
/// 当前居中的业务逻辑下标
@property (nonatomic, assign) NSInteger currentIndex;
@property (nonatomic, assign) NSInteger currentIndex;
/// 当前居中的实际下标
@property (nonatomic, assign) NSInteger infactIndex;
@property (nonatomic, assign) NSInteger infactIndex;
/// (已经废弃)
@property (nonatomic, assign) CGFloat addHeight;
@property (nonatomic, assign) CGFloat addHeight;
/**
自动播放是否暂停
*/
@property (nonatomic, assign) BOOL isPause;
@property (nonatomic, assign) BOOL isPause;
/**
当前展示在中间的cell下标
*/
@property (nonatomic, strong) NSIndexPath *currentIndexPath;
@property (nonatomic, strong) NSIndexPath *currentIndexPath;
@property (nonatomic, strong) MyProxy *timerProxy;
@property (nonatomic, strong) NSTimer *timer;
@end
@implementation CWCarousel
@synthesize carouselView = _carouselView;
- (instancetype)initWithFrame:(CGRect)frame delegate:(id<CWCarouselDelegate>)delegate datasource:(id<CWCarouselDatasource>)datasource flowLayout:(CWFlowLayout *)flowLayout {
CGFloat addHeight = 0;
frame.size.height += addHeight;
self.addHeight = addHeight;
if(self = [super initWithFrame:frame]) {
if (self = [super initWithFrame:frame]) {
_flowLayout = flowLayout;
self.delegate = delegate;
self.datasource = datasource;
......@@ -136,7 +126,7 @@
}
- (void)controllerWillAppear {
if(self.isAuto) {
if (self.isAuto) {
[self resumePlay];
}
[self addNotify];
......@@ -144,7 +134,7 @@
}
- (void)controllerWillDisAppear {
if(self.isAuto) {
if (self.isAuto) {
[self pause];
}
[self removeNotify];
......@@ -162,7 +152,7 @@
}
- (void)dealloc {
NSLog(@"[CWCarousel dealloc]");
DSLog(@"[CWCarousel dealloc]");
[self removeNotify];
[self releaseTimer];
}
......@@ -191,30 +181,27 @@
}
- (void)freshCarousel {
if([self numbers] < 0) {
if ([self numbers] < 0) {
return;
}
[self.carouselView reloadData];
[self layoutIfNeeded];
if (self.endless)
if (self.endless) {
[self.carouselView scrollToItemAtIndexPath:[self originIndexPath] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
else {
if(self.flowLayout.style == CWCarouselStyle_Normal) {
} else {
if (self.flowLayout.style == CWCarouselStyle_Normal) {
[self.carouselView scrollToItemAtIndexPath:self.currentIndexPath = [NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
}
else {
} else {
[self.carouselView scrollToItemAtIndexPath:self.currentIndexPath = [NSIndexPath indexPathForRow:1 inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
}
}
self.carouselView.userInteractionEnabled = YES;
if (self.isAuto) {
[self play];
}
if (self.isAuto) { [self play]; }
}
#pragma mark - < Scroll Delegate >
/// 开始拖拽
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
......@@ -234,9 +221,7 @@
/// 将要结束拖拽
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
NSInteger num = [self numbers];
if (num <= 0) {
return;
}
......@@ -272,10 +257,10 @@
if(velocity.x > 0) {
//左滑,下一张
self.currentIndexPath = [NSIndexPath indexPathForRow:self.currentIndexPath.row + 1 inSection:self.currentIndexPath.section];
}else if (velocity.x < 0) {
} else if (velocity.x < 0) {
//右滑,上一张
self.currentIndexPath = [NSIndexPath indexPathForRow:self.currentIndexPath.row - 1 inSection:self.currentIndexPath.section];
}else if (velocity.x == 0) {
} else if (velocity.x == 0) {
[self velocityZero];
}
}
......@@ -285,8 +270,7 @@
[self cusScrollViewWillBeginDecelerating:YES scroll:scrollView];
}
- (void)cusScrollViewWillBeginDecelerating:(BOOL)animation scroll:(UIScrollView *)scrollView{
- (void)cusScrollViewWillBeginDecelerating:(BOOL)animation scroll:(UIScrollView *)scrollView {
if (self.currentIndexPath == nil) {
return;
}
......@@ -304,13 +288,9 @@
{
// 非无限轮播, 非CWCarouselStyle_Normal样式下, 前后有两张占位cell, 这里需要处理一下.
if (self.currentIndexPath.row == 0 && self.style != CWCarouselStyle_Normal) {
self.currentIndexPath = [NSIndexPath indexPathForRow:1 inSection:self.currentIndexPath.section];
}else if (self.currentIndexPath.row == [self infactNumbers] - 1 && self.style != CWCarouselStyle_Normal) {
} else if (self.currentIndexPath.row == [self infactNumbers] - 1 && self.style != CWCarouselStyle_Normal) {
self.currentIndexPath = [NSIndexPath indexPathForRow:[self infactNumbers] - 2 inSection:self.currentIndexPath.section];
}
}
......@@ -323,7 +303,6 @@
/// 减速完成
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
// 打开交互
scrollView.pagingEnabled = NO;
if(self.isAuto) {
......@@ -333,7 +312,6 @@
/// 滚动动画完成
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
[self cusScrollAnimationEnd:scrollView];
}
......@@ -350,7 +328,7 @@
if (self.endless) {
[self checkOutofBounds];
}
if (self.delegate && [self.delegate respondsToSelector:@selector(CWCarousel:didEndScrollAtIndex:indexPathRow:)]) {
[self.delegate CWCarousel:self didEndScrollAtIndex:[self caculateIndex:self.currentIndexPath.row] indexPathRow:self.currentIndexPath.row];
}
......@@ -363,7 +341,6 @@
#pragma mark - < Logic Helper >
- (NSIndexPath *)originIndexPath {
NSInteger num = [self numbers];
if (num <= 0) {
return [[NSIndexPath alloc] initWithIndex:0];
......@@ -386,7 +363,7 @@
if (centerIndex == 1) {
return self.currentIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
}
// 取中间一组展示
self.currentIndexPath = [NSIndexPath indexPathForRow:centerIndex / 2 * num inSection:0];
return self.currentIndexPath;
......@@ -420,7 +397,7 @@
/**
实际下标转换成业务需求下标
@param factIndex 实际下标
@return 业务需求下标
*/
......@@ -484,8 +461,7 @@
}
- (void)nextCell {
if([self numbers] <= 0) {
if ([self numbers] <= 0) {
return;
}
......@@ -494,17 +470,17 @@
}
NSInteger maxIndex = 1;
if(!self.endless && self.flowLayout.style != CWCarouselStyle_Normal)
if (!self.endless && self.flowLayout.style != CWCarouselStyle_Normal)
{
maxIndex = 2;
}
if(self.currentIndexPath.row < [self infactNumbers] - maxIndex)
if (self.currentIndexPath.row < [self infactNumbers] - maxIndex)
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.currentIndexPath.row + 1 inSection:self.currentIndexPath.section];
[self.carouselView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
self.currentIndexPath = indexPath;
}
else if(!self.endless)
else if (!self.endless)
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:maxIndex - 1 inSection:self.currentIndexPath.section];
[self.carouselView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
......@@ -534,7 +510,7 @@
}
- (void)releaseTimer {
// [self stop];
// [self stop];
if (!self.timer) {
return;
}
......@@ -544,14 +520,13 @@
}
- (void)scrollTo:(NSInteger)index animation:(BOOL)animation {
if (index < 0 || index >= [self numbers]) {
// 防止越界
return;
}
[self stop];
if (index == self.currentIndex) {
[self play];
return;
......@@ -594,9 +569,7 @@
#pragma mark - < Delegate, Datasource >
- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
__weak __typeof(&*self) weakSelf = self;
UICollectionViewCell* (^returnCell)(NSIndexPath *) = ^UICollectionViewCell* (NSIndexPath *idx) {
if (self.datasource && [self.datasource respondsToSelector:@selector(viewForCarousel:indexPath:index:)]) {
UICollectionViewCell *cell = [weakSelf.datasource viewForCarousel:weakSelf indexPath:indexPath index:[weakSelf caculateIndex:indexPath.row]];
......@@ -605,7 +578,6 @@
return nil;
};
if (self.endless) {
return returnCell(indexPath);
}
......@@ -617,9 +589,7 @@
cell.contentView.backgroundColor = [UIColor clearColor];
return cell;
}
return returnCell(indexPath);
}
- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
......@@ -627,8 +597,8 @@
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if(self.delegate &&
[self.delegate respondsToSelector:@selector(CWCarousel:didSelectedAtIndex:)]) {
if (self.delegate &&
[self.delegate respondsToSelector:@selector(CWCarousel:didSelectedAtIndex:)]) {
[self.delegate CWCarousel:self didSelectedAtIndex:[self caculateIndex:indexPath.row]];
}
// 处于动画中时,点击cell,可能会出现cell不居中问题.这里处理下
......@@ -648,7 +618,7 @@
if (_currentIndexPath) {
self.currentIndex = [self caculateIndex:_currentIndexPath.row];
}
if(self.customPageControl == nil)
self.pageControl.currentPage = [self caculateIndex:currentIndexPath.row];
else
......@@ -662,7 +632,6 @@
}
- (void)setCustomPageControl:(UIView<CWCarouselPageControlProtocol> *)customPageControl {
if (_customPageControl == customPageControl) {
return;
}
......@@ -693,7 +662,7 @@
NSDictionary *views = @{@"view" : self.carouselView};
NSDictionary *margins = @{@"top" : @(self.addHeight * 0.5),
@"bottom" : @(self.addHeight * 0.5)
};
};
NSString *str = @"H:|-0-[view]-0-|";
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:str
options:kNilOptions
......@@ -713,7 +682,6 @@
return _carouselView;
}
- (CWCarouselStyle)style {
if(self.flowLayout) {
return self.flowLayout.style;
......@@ -721,10 +689,9 @@
return CWCarouselStyle_Unknow;
}
/**
Description
@return 业务需求需要展示轮播图个数
*/
- (NSInteger)numbers {
......@@ -744,17 +711,16 @@
/**
轮播图实际加载视图个数
@return 轮播图实际加载视图个数
*/
- (NSInteger)infactNumbers {
NSInteger num = [self numbers];
if ( num <= 0) {
return 0;
}
[self.carouselView setScrollEnabled:YES];
if (self.endless) {
......@@ -800,6 +766,7 @@
- (NSString *)version {
return @"1.1.9";
}
@end
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!