Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
陈高翔
/
DreamSleep-iOS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 859a366c
由
cgx
编写于
2022-06-18 16:50:23 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
优化轮播图自动无限循环播放
1 个父辈
3beeb052
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
85 行增加
和
99 行删除
DreamSleep/DreamSleep.xcodeproj/project.pbxproj
DreamSleep/DreamSleep/Class/HomeModule/Home/Controller/HomeViewController.m
DreamSleep/DreamSleep/Class/HomeModule/Home/View/DSHomeView.h
DreamSleep/DreamSleep/Class/HomeModule/Home/View/DSHomeView.m
DreamSleep/DreamSleep/Class/HomeModule/Home/View/HomeHeaderView.h
DreamSleep/DreamSleep/Class/HomeModule/Home/View/HomeHeaderView.m
DreamSleep/DreamSleep/Class/HomeModule/Home/View/SafeHelperCollectionViewCell.m
DreamSleep/DreamSleep/Class/HomeModule/UnityGame/UnityGameController.m
DreamSleep/DreamSleep/Class/ProfileModule/UserLogin/LoginController.m
DreamSleep/DreamSleep/Vendors/CWCarousel/CWCarousel.h
DreamSleep/DreamSleep/Vendors/CWCarousel/CWCarousel.m
DreamSleep/DreamSleep.xcodeproj/project.pbxproj
查看文件 @
859a366
...
@@ -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;
...
...
DreamSleep/DreamSleep/Class/HomeModule/Home/Controller/HomeViewController.m
查看文件 @
859a366
...
@@ -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
];
}
}
...
...
DreamSleep/DreamSleep/Class/HomeModule/Home/View/DSHomeView.h
查看文件 @
859a366
...
@@ -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
...
...
DreamSleep/DreamSleep/Class/HomeModule/Home/View/DSHomeView.m
查看文件 @
859a366
...
@@ -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
;
...
...
DreamSleep/DreamSleep/Class/HomeModule/Home/View/HomeHeaderView.h
查看文件 @
859a366
...
@@ -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
DreamSleep/DreamSleep/Class/HomeModule/Home/View/HomeHeaderView.m
查看文件 @
859a366
...
@@ -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
;
...
...
DreamSleep/DreamSleep/Class/HomeModule/Home/View/SafeHelperCollectionViewCell.m
查看文件 @
859a366
...
@@ -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
;
...
...
DreamSleep/DreamSleep/Class/HomeModule/UnityGame/UnityGameController.m
查看文件 @
859a366
...
@@ -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
DreamSleep/DreamSleep/Class/ProfileModule/UserLogin/LoginController.m
查看文件 @
859a366
...
@@ -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
...
...
DreamSleep/DreamSleep/Vendors/CWCarousel/CWCarousel.h
查看文件 @
859a366
...
@@ -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
...
...
DreamSleep/DreamSleep/Vendors/CWCarousel/CWCarousel.m
查看文件 @
859a366
...
@@ -9,13 +9,12 @@
...
@@ -9,13 +9,12 @@
#import "CWCarousel.h"
#import "CWCarousel.h"
@interface
CWCarouselCollectionView
()
@interface
CWCarouselCollectionView
()
@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
{
N
SLog
(
@"[CWCarouselCollectionView dealloc]"
);
D
SLog
(
@"[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,43 +72,38 @@
...
@@ -77,43 +72,38 @@
@end
@end
@interface
CWCarousel
()
<
UICollectionViewDelegate
,
UICollectionViewDataSource
>
{
@interface
CWCarousel
()
<
UICollectionViewDelegate
,
UICollectionViewDataSource
>
{
}
}
/// collectionView
/// collectionView
@property
(
nonatomic
,
strong
)
CWCarouselCollectionView
*
carouselView
;
@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下标
当前展示在中间的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
{
N
SLog
(
@"[CWCarousel dealloc]"
);
D
SLog
(
@"[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
];
}
}
...
@@ -350,7 +328,7 @@
...
@@ -350,7 +328,7 @@
if
(
self
.
endless
)
{
if
(
self
.
endless
)
{
[
self
checkOutofBounds
];
[
self
checkOutofBounds
];
}
}
if
(
self
.
delegate
&&
[
self
.
delegate
respondsToSelector
:
@selector
(
CWCarousel
:
didEndScrollAtIndex
:
indexPathRow
:
)])
{
if
(
self
.
delegate
&&
[
self
.
delegate
respondsToSelector
:
@selector
(
CWCarousel
:
didEndScrollAtIndex
:
indexPathRow
:
)])
{
[
self
.
delegate
CWCarousel
:
self
didEndScrollAtIndex
:[
self
caculateIndex
:
self
.
currentIndexPath
.
row
]
indexPathRow
:
self
.
currentIndexPath
.
row
];
[
self
.
delegate
CWCarousel
:
self
didEndScrollAtIndex
:[
self
caculateIndex
:
self
.
currentIndexPath
.
row
]
indexPathRow
:
self
.
currentIndexPath
.
row
];
}
}
...
@@ -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
];
...
@@ -386,7 +363,7 @@
...
@@ -386,7 +363,7 @@
if
(
centerIndex
==
1
)
{
if
(
centerIndex
==
1
)
{
return
self
.
currentIndexPath
=
[
NSIndexPath
indexPathForRow
:
0
inSection
:
0
];
return
self
.
currentIndexPath
=
[
NSIndexPath
indexPathForRow
:
0
inSection
:
0
];
}
}
// 取中间一组展示
// 取中间一组展示
self
.
currentIndexPath
=
[
NSIndexPath
indexPathForRow
:
centerIndex
/
2
*
num
inSection
:
0
];
self
.
currentIndexPath
=
[
NSIndexPath
indexPathForRow
:
centerIndex
/
2
*
num
inSection
:
0
];
return
self
.
currentIndexPath
;
return
self
.
currentIndexPath
;
...
@@ -420,7 +397,7 @@
...
@@ -420,7 +397,7 @@
/**
/**
实际下标转换成业务需求下标
实际下标转换成业务需求下标
@param factIndex 实际下标
@param factIndex 实际下标
@return 业务需求下标
@return 业务需求下标
*/
*/
...
@@ -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,14 +520,13 @@
...
@@ -544,14 +520,13 @@
}
}
-
(
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
;
}
}
[
self
stop
];
[
self
stop
];
if
(
index
==
self
.
currentIndex
)
{
if
(
index
==
self
.
currentIndex
)
{
[
self
play
];
[
self
play
];
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,8 +597,8 @@
...
@@ -627,8 +597,8 @@
}
}
-
(
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
]];
}
}
// 处于动画中时,点击cell,可能会出现cell不居中问题.这里处理下
// 处于动画中时,点击cell,可能会出现cell不居中问题.这里处理下
...
@@ -648,7 +618,7 @@
...
@@ -648,7 +618,7 @@
if
(
_currentIndexPath
)
{
if
(
_currentIndexPath
)
{
self
.
currentIndex
=
[
self
caculateIndex
:
_currentIndexPath
.
row
];
self
.
currentIndex
=
[
self
caculateIndex
:
_currentIndexPath
.
row
];
}
}
if
(
self
.
customPageControl
==
nil
)
if
(
self
.
customPageControl
==
nil
)
self
.
pageControl
.
currentPage
=
[
self
caculateIndex
:
currentIndexPath
.
row
];
self
.
pageControl
.
currentPage
=
[
self
caculateIndex
:
currentIndexPath
.
row
];
else
else
...
@@ -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
;
}
}
...
@@ -693,7 +662,7 @@
...
@@ -693,7 +662,7 @@
NSDictionary
*
views
=
@{
@"view"
:
self
.
carouselView
};
NSDictionary
*
views
=
@{
@"view"
:
self
.
carouselView
};
NSDictionary
*
margins
=
@{
@"top"
:
@
(
self
.
addHeight
*
0
.
5
),
NSDictionary
*
margins
=
@{
@"top"
:
@
(
self
.
addHeight
*
0
.
5
),
@"bottom"
:
@
(
self
.
addHeight
*
0
.
5
)
@"bottom"
:
@
(
self
.
addHeight
*
0
.
5
)
};
};
NSString
*
str
=
@"H:|-0-[view]-0-|"
;
NSString
*
str
=
@"H:|-0-[view]-0-|"
;
[
self
addConstraints
:[
NSLayoutConstraint
constraintsWithVisualFormat
:
str
[
self
addConstraints
:[
NSLayoutConstraint
constraintsWithVisualFormat
:
str
options
:
kNilOptions
options
:
kNilOptions
...
@@ -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,10 +689,9 @@
...
@@ -721,10 +689,9 @@
return
CWCarouselStyle_Unknow
;
return
CWCarouselStyle_Unknow
;
}
}
/**
/**
Description
Description
@return 业务需求需要展示轮播图个数
@return 业务需求需要展示轮播图个数
*/
*/
-
(
NSInteger
)
numbers
{
-
(
NSInteger
)
numbers
{
...
@@ -744,17 +711,16 @@
...
@@ -744,17 +711,16 @@
/**
/**
轮播图实际加载视图个数
轮播图实际加载视图个数
@return 轮播图实际加载视图个数
@return 轮播图实际加载视图个数
*/
*/
-
(
NSInteger
)
infactNumbers
{
-
(
NSInteger
)
infactNumbers
{
NSInteger
num
=
[
self
numbers
];
NSInteger
num
=
[
self
numbers
];
if
(
num
<=
0
)
{
if
(
num
<=
0
)
{
return
0
;
return
0
;
}
}
[
self
.
carouselView
setScrollEnabled
:
YES
];
[
self
.
carouselView
setScrollEnabled
:
YES
];
if
(
self
.
endless
)
{
if
(
self
.
endless
)
{
...
@@ -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!
Cancel
请
注册
或
登录
后发表评论