Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions SDCycleScrollView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
TargetAttributes = {
9900D16D1ABEB2490077A6CB = {
CreatedOnToolsVersion = 6.1;

ProvisioningStyle = Automatic;
};
9900D1861ABEB2490077A6CB = {
Expand Down Expand Up @@ -556,11 +557,13 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";

"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = SDCycleScrollView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "-.SDCycleScrollView";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -574,11 +577,13 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";

"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = SDCycleScrollView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "-.SDCycleScrollView";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
10 changes: 10 additions & 0 deletions SDCycleScrollView/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down
12 changes: 6 additions & 6 deletions SDCycleScrollView/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>-.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand All @@ -22,6 +22,11 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand All @@ -34,10 +39,5 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
33 changes: 29 additions & 4 deletions SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//

// SDCycleScrollView.m
// SDCycleScrollView
//
Expand Down Expand Up @@ -38,6 +38,7 @@

#define kCycleScrollViewInitialPageControlDotSize CGSizeMake(10, 10)


NSString * const ID = @"SDCycleScrollViewCell";

@interface SDCycleScrollView () <UICollectionViewDataSource, UICollectionViewDelegate>
Expand Down Expand Up @@ -298,7 +299,7 @@ - (void)setImagePathsGroup:(NSArray *)imagePathsGroup

_imagePathsGroup = imagePathsGroup;

_totalItemsCount = self.infiniteLoop ? self.imagePathsGroup.count * 100 : self.imagePathsGroup.count;
_totalItemsCount = self.infiniteLoop ? self.imagePathsGroup.count * 500 : self.imagePathsGroup.count;

if (imagePathsGroup.count > 1) { // 由于 !=1 包含count == 0等情况
self.mainView.scrollEnabled = YES;
Expand Down Expand Up @@ -578,7 +579,6 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
}

NSString *imagePath = self.imagePathsGroup[itemIndex];

if (!self.onlyDisplayText && [imagePath isKindOfClass:[NSString class]]) {
if ([imagePath hasPrefix:@"http"]) {
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:imagePath] placeholderImage:self.placeholderImage];
Expand Down Expand Up @@ -608,7 +608,6 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
cell.clipsToBounds = YES;
cell.onlyDisplayText = self.onlyDisplayText;
}

return cell;
}

Expand All @@ -630,6 +629,27 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
if (!self.imagePathsGroup.count) return; // 解决清除timer时偶尔会出现的问题
int itemIndex = [self currentIndex];
int indexOnPageControl = [self pageControlIndexWithCurrentCellIndex:itemIndex];
if (_flowLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal && _infiniteLoop) {
if (scrollView.contentOffset.x >= (_totalItemsCount - 1) * (_flowLayout.itemSize.width) ){
[_mainView setContentOffset:CGPointMake((_totalItemsCount/2 - 1)*_flowLayout.itemSize.width, 0)];

}
if (scrollView.contentOffset.x <= 0.0){
[_mainView setContentOffset:CGPointMake(_totalItemsCount/2 *_flowLayout.itemSize.width, 0)];

}
}

if (_flowLayout.scrollDirection == UICollectionViewScrollDirectionVertical && _infiniteLoop) {
if(scrollView.contentOffset.y >= (_totalItemsCount - 1) * (_flowLayout.itemSize.height)) {

[_mainView setContentOffset:CGPointMake(0, (_totalItemsCount/2 - 1)*_flowLayout.itemSize.height)];
}
if (scrollView.contentOffset.y <= 0 ){
[_mainView setContentOffset:CGPointMake(0, _totalItemsCount/2 *_flowLayout.itemSize.height)];

}
}

if ([self.pageControl isKindOfClass:[TAPageControl class]]) {
TAPageControl *pageControl = (TAPageControl *)_pageControl;
Expand All @@ -645,13 +665,18 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
if (self.autoScroll) {
[self invalidateTimer];
}



}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (self.autoScroll) {
[self setupTimer];
}


}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
Expand Down