Commit 859a366c cgx

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

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