21 Commits

Author SHA1 Message Date
hryk224 1e0ae10e2d Merge pull request #12 from hryk224/1.4.0
1.3.1
2017-02-17 05:04:51 +09:00
hyyk224 105846f1d2 1.3.1 2017-02-17 05:04:12 +09:00
hryk224 bcc954d105 Update podspec 2017-01-12 10:40:48 +09:00
hryk224 543b75cf56 Merge pull request #11 from jwardle/master
selectItem implementation
2017-01-12 10:38:49 +09:00
James Wardle 4bd0209ccb Update InfiniteCollectionView.swift
~ Enhanced the implementation to correct the index.
2017-01-10 21:59:52 +00:00
James Wardle 6fcd6a52e2 Update InfiniteCollectionView.swift
+ Added selectItem override to allow programatic selection of items - previously this was not considered and broken.
2017-01-09 22:01:02 +00:00
hryk224 d5afefb36d Updated 1.2.1 2017-01-05 11:14:02 +09:00
hryk224 118f9c3a45 Small changed 2017-01-05 11:12:06 +09:00
hryk224 af34834fdf Merge pull request #9 from hryk224/fix/remove_cellwidth
Removed `var cellWidth`
2016-12-05 23:38:57 +09:00
hyyk224 b82efbc483 Add deprecated message for warning 2016-12-05 23:38:21 +09:00
hryk224 037a932409 Removed unneeded property 2016-11-17 14:51:26 +09:00
hryk224 1c9d9cada6 Add swift vetsion file 2016-10-19 17:56:28 +09:00
hryk224 ed62ccbe9b Merge pull request #6 from hryk224/swift3
Swift3
2016-10-19 17:24:13 +09:00
hryk224 98a8b65b83 Merge pull request #8 from hryk224/feature/swift3_orientaion
Support orientation changed
2016-10-19 17:16:50 +09:00
hryk224 7f7e5fd1df Support orientation changed 2016-10-19 17:10:31 +09:00
hryk224 d42d494a37 Updated: README, Example 2016-10-14 10:52:00 +09:00
hryk224 496eaaf907 Merge pull request #7 from AxialExchange/swift3
Changed delegate call from collectionView to infiniteCollectionView
2016-10-14 10:07:43 +09:00
Raf Cabezas 60cc91e726 Changed delegate call from collectionView to infiniteCollectionView
This removes potential error:
"Objective-C method 'collectionView:didSelectItemAtIndexPath:' provided by method 'collectionView(_:didSelectItemAt:)' does not match the requirement's selector ('collectionView:didSelectItemAt:')"
2016-10-13 15:27:59 -04:00
hryk224 a94aa29ab6 Support ios8 2016-09-26 11:57:27 +09:00
hryk224 a5535d0d86 Support swift3 2016-09-21 19:37:43 +09:00
hryk224 f0c4a4d174 Update README.md 2016-05-20 07:27:31 +09:00
26 changed files with 675 additions and 495 deletions
+2 -1
View File
@@ -20,4 +20,5 @@ DerivedData
*.ipa
*.app
*.xccheckout
*.xccheckout
sort-Xcode-project-file
+1
View File
@@ -0,0 +1 @@
3.0
+71 -35
View File
@@ -18,21 +18,21 @@
935BD6E51CE26F0B00E5FDF7 /* Pattern1ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935BD6DE1CE26F0B00E5FDF7 /* Pattern1ViewController.swift */; };
935BD6E61CE26F0B00E5FDF7 /* Pattern2.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 935BD6DF1CE26F0B00E5FDF7 /* Pattern2.storyboard */; };
935BD6E71CE26F0B00E5FDF7 /* Pattern2ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935BD6E01CE26F0B00E5FDF7 /* Pattern2ViewController.swift */; };
935BD71D1CE26FBF00E5FDF7 /* InfiniteCollectionView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 935BD71C1CE26FB600E5FDF7 /* InfiniteCollectionView.framework */; };
935BD71E1CE26FBF00E5FDF7 /* InfiniteCollectionView.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 935BD71C1CE26FB600E5FDF7 /* InfiniteCollectionView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
EDA05AD81D92901C00F7C2C5 /* InfiniteCollectionView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDA05AD71D92901900F7C2C5 /* InfiniteCollectionView.framework */; };
EDA05AD91D92901C00F7C2C5 /* InfiniteCollectionView.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EDA05AD71D92901900F7C2C5 /* InfiniteCollectionView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
935BD71B1CE26FB600E5FDF7 /* PBXContainerItemProxy */ = {
EDA05AD61D92901900F7C2C5 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 935BD7171CE26FB600E5FDF7 /* InfiniteCollectionView.xcodeproj */;
containerPortal = EDA05AD21D92901900F7C2C5 /* InfiniteCollectionView.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 935BD70D1CE26F8E00E5FDF7;
remoteInfo = InfiniteCollectionView;
};
935BD71F1CE26FBF00E5FDF7 /* PBXContainerItemProxy */ = {
EDA05ADA1D92901C00F7C2C5 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 935BD7171CE26FB600E5FDF7 /* InfiniteCollectionView.xcodeproj */;
containerPortal = EDA05AD21D92901900F7C2C5 /* InfiniteCollectionView.xcodeproj */;
proxyType = 1;
remoteGlobalIDString = 935BD70C1CE26F8E00E5FDF7;
remoteInfo = InfiniteCollectionView;
@@ -46,7 +46,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
935BD71E1CE26FBF00E5FDF7 /* InfiniteCollectionView.framework in Embed Frameworks */,
EDA05AD91D92901C00F7C2C5 /* InfiniteCollectionView.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
@@ -67,7 +67,7 @@
935BD6DE1CE26F0B00E5FDF7 /* Pattern1ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Pattern1ViewController.swift; sourceTree = "<group>"; };
935BD6DF1CE26F0B00E5FDF7 /* Pattern2.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Pattern2.storyboard; sourceTree = "<group>"; };
935BD6E01CE26F0B00E5FDF7 /* Pattern2ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Pattern2ViewController.swift; sourceTree = "<group>"; };
935BD7171CE26FB600E5FDF7 /* InfiniteCollectionView.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = InfiniteCollectionView.xcodeproj; path = ../InfiniteCollectionView.xcodeproj; sourceTree = "<group>"; };
EDA05AD21D92901900F7C2C5 /* InfiniteCollectionView.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = InfiniteCollectionView.xcodeproj; path = ../InfiniteCollectionView.xcodeproj; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -75,7 +75,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
935BD71D1CE26FBF00E5FDF7 /* InfiniteCollectionView.framework in Frameworks */,
EDA05AD81D92901C00F7C2C5 /* InfiniteCollectionView.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -85,8 +85,8 @@
935BD6BC1CE26EB600E5FDF7 = {
isa = PBXGroup;
children = (
935BD7171CE26FB600E5FDF7 /* InfiniteCollectionView.xcodeproj */,
935BD6C71CE26EB600E5FDF7 /* Example */,
EDA05AD11D92901900F7C2C5 /* Frameworks */,
935BD6C61CE26EB600E5FDF7 /* Products */,
);
sourceTree = "<group>";
@@ -102,26 +102,50 @@
935BD6C71CE26EB600E5FDF7 /* Example */ = {
isa = PBXGroup;
children = (
ED510E6D1DDD513200470C8B /* Pattern1 */,
ED510E6E1DDD513F00470C8B /* Pattern2 */,
935BD6C81CE26EB600E5FDF7 /* AppDelegate.swift */,
935BD6CF1CE26EB600E5FDF7 /* Assets.xcassets */,
935BD6DA1CE26F0B00E5FDF7 /* ImageCollectionViewCell.swift */,
935BD6DB1CE26F0B00E5FDF7 /* ImageCollectionViewCell.xib */,
935BD6DC1CE26F0B00E5FDF7 /* MainViewController.swift */,
935BD6DD1CE26F0B00E5FDF7 /* Pattern1.storyboard */,
935BD6DE1CE26F0B00E5FDF7 /* Pattern1ViewController.swift */,
935BD6DF1CE26F0B00E5FDF7 /* Pattern2.storyboard */,
935BD6E01CE26F0B00E5FDF7 /* Pattern2ViewController.swift */,
935BD6CC1CE26EB600E5FDF7 /* Main.storyboard */,
935BD6CF1CE26EB600E5FDF7 /* Assets.xcassets */,
935BD6D11CE26EB600E5FDF7 /* LaunchScreen.storyboard */,
935BD6D41CE26EB600E5FDF7 /* Info.plist */,
935BD6D11CE26EB600E5FDF7 /* LaunchScreen.storyboard */,
935BD6CC1CE26EB600E5FDF7 /* Main.storyboard */,
935BD6DC1CE26F0B00E5FDF7 /* MainViewController.swift */,
);
path = Example;
sourceTree = "<group>";
};
935BD7181CE26FB600E5FDF7 /* Products */ = {
ED510E6D1DDD513200470C8B /* Pattern1 */ = {
isa = PBXGroup;
children = (
935BD71C1CE26FB600E5FDF7 /* InfiniteCollectionView.framework */,
935BD6DD1CE26F0B00E5FDF7 /* Pattern1.storyboard */,
935BD6DE1CE26F0B00E5FDF7 /* Pattern1ViewController.swift */,
);
name = Pattern1;
sourceTree = "<group>";
};
ED510E6E1DDD513F00470C8B /* Pattern2 */ = {
isa = PBXGroup;
children = (
935BD6DF1CE26F0B00E5FDF7 /* Pattern2.storyboard */,
935BD6E01CE26F0B00E5FDF7 /* Pattern2ViewController.swift */,
);
name = Pattern2;
sourceTree = "<group>";
};
EDA05AD11D92901900F7C2C5 /* Frameworks */ = {
isa = PBXGroup;
children = (
EDA05AD21D92901900F7C2C5 /* InfiniteCollectionView.xcodeproj */,
);
name = Frameworks;
sourceTree = "<group>";
};
EDA05AD31D92901900F7C2C5 /* Products */ = {
isa = PBXGroup;
children = (
EDA05AD71D92901900F7C2C5 /* InfiniteCollectionView.framework */,
);
name = Products;
sourceTree = "<group>";
@@ -141,7 +165,7 @@
buildRules = (
);
dependencies = (
935BD7201CE26FBF00E5FDF7 /* PBXTargetDependency */,
EDA05ADB1D92901C00F7C2C5 /* PBXTargetDependency */,
);
name = Example;
productName = Example;
@@ -155,11 +179,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0810;
ORGANIZATIONNAME = "hiroyuki yoshida";
TargetAttributes = {
935BD6C41CE26EB600E5FDF7 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0800;
};
};
};
@@ -176,8 +201,8 @@
projectDirPath = "";
projectReferences = (
{
ProductGroup = 935BD7181CE26FB600E5FDF7 /* Products */;
ProjectRef = 935BD7171CE26FB600E5FDF7 /* InfiniteCollectionView.xcodeproj */;
ProductGroup = EDA05AD31D92901900F7C2C5 /* Products */;
ProjectRef = EDA05AD21D92901900F7C2C5 /* InfiniteCollectionView.xcodeproj */;
},
);
projectRoot = "";
@@ -188,11 +213,11 @@
/* End PBXProject section */
/* Begin PBXReferenceProxy section */
935BD71C1CE26FB600E5FDF7 /* InfiniteCollectionView.framework */ = {
EDA05AD71D92901900F7C2C5 /* InfiniteCollectionView.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
path = InfiniteCollectionView.framework;
remoteRef = 935BD71B1CE26FB600E5FDF7 /* PBXContainerItemProxy */;
remoteRef = EDA05AD61D92901900F7C2C5 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */
@@ -202,12 +227,12 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
935BD6E61CE26F0B00E5FDF7 /* Pattern2.storyboard in Resources */,
935BD6D31CE26EB600E5FDF7 /* LaunchScreen.storyboard in Resources */,
935BD6D01CE26EB600E5FDF7 /* Assets.xcassets in Resources */,
935BD6E41CE26F0B00E5FDF7 /* Pattern1.storyboard in Resources */,
935BD6E21CE26F0B00E5FDF7 /* ImageCollectionViewCell.xib in Resources */,
935BD6D31CE26EB600E5FDF7 /* LaunchScreen.storyboard in Resources */,
935BD6CE1CE26EB600E5FDF7 /* Main.storyboard in Resources */,
935BD6E41CE26F0B00E5FDF7 /* Pattern1.storyboard in Resources */,
935BD6E61CE26F0B00E5FDF7 /* Pattern2.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -218,21 +243,21 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
935BD6C91CE26EB600E5FDF7 /* AppDelegate.swift in Sources */,
935BD6E11CE26F0B00E5FDF7 /* ImageCollectionViewCell.swift in Sources */,
935BD6E31CE26F0B00E5FDF7 /* MainViewController.swift in Sources */,
935BD6E51CE26F0B00E5FDF7 /* Pattern1ViewController.swift in Sources */,
935BD6E11CE26F0B00E5FDF7 /* ImageCollectionViewCell.swift in Sources */,
935BD6E71CE26F0B00E5FDF7 /* Pattern2ViewController.swift in Sources */,
935BD6C91CE26EB600E5FDF7 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
935BD7201CE26FBF00E5FDF7 /* PBXTargetDependency */ = {
EDA05ADB1D92901C00F7C2C5 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = InfiniteCollectionView;
targetProxy = 935BD71F1CE26FBF00E5FDF7 /* PBXContainerItemProxy */;
targetProxy = EDA05ADA1D92901C00F7C2C5 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
@@ -270,8 +295,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -293,7 +320,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -315,8 +342,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -332,9 +361,10 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
@@ -342,22 +372,28 @@
935BD6D81CE26EB600E5FDF7 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Example/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.github.hryk224.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
935BD6D91CE26EB600E5FDF7 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Example/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.github.hryk224.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
+6 -6
View File
@@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
@@ -13,10 +15,9 @@
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
+6 -6
View File
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="ptf-1R-ZgN">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="ptf-1R-ZgN">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
@@ -30,15 +31,14 @@
<viewControllerLayoutGuide type="bottom" id="WMJ-rH-CQa"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="HUl-2W-LaH">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="I2m-0B-Ns8">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</tableView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="I2m-0B-Ns8" secondAttribute="trailing" id="0tu-qe-S7J"/>
<constraint firstItem="I2m-0B-Ns8" firstAttribute="leading" secondItem="HUl-2W-LaH" secondAttribute="leading" id="g0I-Ut-iu3"/>
@@ -12,8 +12,8 @@ final class ImageCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
static let identifier = "ImageCollectionViewCell"
static let nib = UINib(nibName: "ImageCollectionViewCell", bundle: nil)
func configure(dequeueIndexPath dequeueIndexPath: NSIndexPath) {
let image = UIImage(named: String(dequeueIndexPath.item))
func configure(indexPath: IndexPath) {
let image = UIImage(named: String(indexPath.item))
imageView.image = image
setNeedsLayout()
layoutIfNeeded()
+7 -7
View File
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
@@ -11,12 +13,10 @@
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="6aC-HR-aM0">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
</imageView>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="6aC-HR-aM0"/>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<constraints>
<constraint firstItem="6aC-HR-aM0" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" id="hnJ-jX-Q7o"/>
@@ -27,7 +27,7 @@
<connections>
<outlet property="imageView" destination="6aC-HR-aM0" id="4uF-jM-h1C"/>
</connections>
<point key="canvasLocation" x="839" y="363"/>
<point key="canvasLocation" x="27" y="27"/>
</collectionViewCell>
</objects>
</document>
+22 -14
View File
@@ -12,39 +12,47 @@ import InfiniteCollectionView
final class MainViewController: UIViewController {
var patterns = ["pattern1", "pattern2"]
let identifier = "tableViewCell"
var cellHeight: CGFloat {
return (UIScreen.main.bounds.height - 64) / CGFloat(patterns.count)
}
@IBOutlet weak var tableView: UITableView! {
didSet {
tableView.delegate = self
tableView.dataSource = self
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: identifier)
tableView.rowHeight = 100
tableView.estimatedRowHeight = 100
tableView.register(UITableViewCell.self, forCellReuseIdentifier: identifier)
tableView.rowHeight = cellHeight
tableView.estimatedRowHeight = cellHeight
}
}
override func viewWillAppear(animated: Bool) {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let selectedIndexPath = tableView.indexPathForSelectedRow {
tableView.deselectRowAtIndexPath(selectedIndexPath, animated: true)
}
guard let selectedIndexPath = tableView.indexPathForSelectedRow else { return }
tableView.deselectRow(at: selectedIndexPath, animated: true)
}
}
// MARK: - UITableViewDelegate, UITableViewDataSource
extension MainViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return patterns.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(identifier)!
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: identifier)!
cell.textLabel?.text = patterns[indexPath.row]
cell.textLabel?.textAlignment = .center
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 24)
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == 0 {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.row {
case 0:
let controller = Pattern1ViewController.createFromStoryboard()
navigationController?.pushViewController(controller, animated: true)
} else if indexPath.row == 1 {
case 1:
let controller = Pattern2ViewController.createFromStoryboard()
navigationController?.pushViewController(controller, animated: true)
default:
break
}
}
}
}
+19 -15
View File
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="jtB-7l-rQl">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="jtB-7l-rQl">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Pattern1 View Controller-->
@@ -14,12 +18,12 @@
<viewControllerLayoutGuide type="bottom" id="rTP-xN-QW3"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="fk8-nc-mgC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" pagingEnabled="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="Lwf-cA-VEr" customClass="InfiniteCollectionView" customModule="InfiniteCollectionView">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" minimumLineSpacing="0.0" minimumInteritemSpacing="0.0" id="9XM-Ng-ou9">
<size key="itemSize" width="600" height="600"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
@@ -28,23 +32,23 @@
</collectionViewFlowLayout>
<cells/>
</collectionView>
<view alpha="0.5" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="QjU-up-8Sl">
<rect key="frame" x="0.0" y="543" width="600" height="37"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<view userInteractionEnabled="NO" alpha="0.5" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="QjU-up-8Sl">
<rect key="frame" x="0.0" y="610" width="375" height="37"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="37" id="Pl4-pn-Jed"/>
</constraints>
</view>
<pageControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" numberOfPages="3" translatesAutoresizingMaskIntoConstraints="NO" id="RxI-o2-lRZ">
<rect key="frame" x="0.0" y="543" width="600" height="37"/>
<pageControl opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" numberOfPages="3" translatesAutoresizingMaskIntoConstraints="NO" id="RxI-o2-lRZ">
<rect key="frame" x="0.0" y="610" width="375" height="37"/>
<constraints>
<constraint firstAttribute="height" constant="37" id="L4v-Uu-0PK"/>
</constraints>
<color key="pageIndicatorTintColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="currentPageIndicatorTintColor" red="0.75686274509999996" green="0.1960784314" blue="0.15686274510000001" alpha="1" colorSpace="calibratedRGB"/>
<color key="pageIndicatorTintColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="currentPageIndicatorTintColor" red="0.75686274509999996" green="0.1960784314" blue="0.15686274510000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</pageControl>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="QjU-up-8Sl" secondAttribute="trailing" id="12W-C1-v9R"/>
<constraint firstAttribute="trailing" secondItem="RxI-o2-lRZ" secondAttribute="trailing" id="I7I-K3-VLb"/>
@@ -66,7 +70,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="6qE-8b-tDF" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="584" y="352"/>
<point key="canvasLocation" x="-468" y="96"/>
</scene>
</scenes>
</document>
+27 -13
View File
@@ -10,44 +10,58 @@ import UIKit
import InfiniteCollectionView
final class Pattern1ViewController: UIViewController {
var items = ["1", "2", "3", "4"]
var itemsCount: Int = 5
@IBOutlet weak var collectionView: InfiniteCollectionView! {
didSet {
collectionView.infiniteDataSource = self
collectionView.infiniteDelegate = self
collectionView.cellWidth = UIScreen.mainScreen().bounds.width
collectionView.registerNib(ImageCollectionViewCell.nib, forCellWithReuseIdentifier: ImageCollectionViewCell.identifier)
collectionView.register(ImageCollectionViewCell.nib, forCellWithReuseIdentifier: ImageCollectionViewCell.identifier)
}
}
@IBOutlet weak var layout: UICollectionViewFlowLayout! {
didSet {
layout.itemSize = CGSize(width: UIScreen.mainScreen().bounds.width, height: UIScreen.mainScreen().bounds.height)
layout.itemSize = UIScreen.main.bounds.size
}
}
@IBOutlet weak var pageControl: UIPageControl! {
didSet {
pageControl.numberOfPages = items.count
pageControl.numberOfPages = itemsCount
}
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
NotificationCenter.default.addObserver(self, selector: #selector(Pattern1ViewController.rotate(_:)), name: .UIDeviceOrientationDidChange, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self, name: .UIDeviceOrientationDidChange, object: nil)
}
static func createFromStoryboard() -> Pattern1ViewController {
let storyboard = UIStoryboard(name: "Pattern1", bundle: nil)
return storyboard.instantiateInitialViewController() as! Pattern1ViewController
}
func rotate(_ notification: Notification) {
layout.itemSize = UIScreen.main.bounds.size
layout.invalidateLayout()
collectionView.rotate(notification)
collectionView.layoutIfNeeded()
collectionView.setNeedsLayout()
}
}
// MARK: - InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate
extension Pattern1ViewController: InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate {
func numberOfItems(collectionView: UICollectionView) -> Int {
return items.count
func number(ofItems collectionView: UICollectionView) -> Int {
return itemsCount
}
func cellForItemAtIndexPath(collectionView: UICollectionView, dequeueIndexPath: NSIndexPath, indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(ImageCollectionViewCell.identifier, forIndexPath: dequeueIndexPath) as! ImageCollectionViewCell
cell.configure(dequeueIndexPath: indexPath)
func collectionView(_ collectionView: UICollectionView, dequeueForItemAt dequeueIndexPath: IndexPath, cellForItemAt usableIndexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ImageCollectionViewCell.identifier, for: dequeueIndexPath) as! ImageCollectionViewCell
cell.configure(indexPath: usableIndexPath)
return cell
}
func didSelectCellAtIndexPath(collectionView: UICollectionView, indexPath: NSIndexPath) {
func infiniteCollectionView(_ collectionView: UICollectionView, didSelectItemAt usableIndexPath: IndexPath) {
print("didSelectItemAt: \(usableIndexPath.item)")
}
func didUpdatePageIndex(index: Int) {
pageControl.currentPage = index
func scrollView(_ scrollView: UIScrollView, pageIndex: Int) {
pageControl.currentPage = pageIndex
}
}
+34 -32
View File
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="OWH-Uo-QHx">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="OWH-Uo-QHx">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Pattern2 View Controller-->
@@ -14,23 +18,23 @@
<viewControllerLayoutGuide type="bottom" id="aif-qL-b6r"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="hwa-cs-SAI">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="blK-sK-Rl8">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="InfiniteTableViewCell" rowHeight="161" id="1U1-fg-z8H" customClass="InfiniteTableViewCell" customModule="Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="600" height="161"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="InfiniteTableViewCell" rowHeight="240" id="1U1-fg-z8H" customClass="InfiniteTableViewCell" customModule="Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="375" height="240"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="1U1-fg-z8H" id="FjB-bh-baH">
<rect key="frame" x="0.0" y="0.0" width="600" height="160"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="239"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" pagingEnabled="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="g4o-O8-u5y" customClass="InfiniteCollectionView" customModule="InfiniteCollectionView">
<rect key="frame" x="0.0" y="0.0" width="600" height="160"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="240"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" minimumLineSpacing="0.0" minimumInteritemSpacing="0.0" id="JvE-3O-3Xs">
<size key="itemSize" width="50" height="50"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
@@ -39,17 +43,16 @@
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="ImageCollectionViewCell" id="PWv-9R-TGh" customClass="ImageCollectionViewCell" customModule="Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="600" height="160"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="240"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="600" height="160"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="240"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="m9D-ne-YCP">
<rect key="frame" x="0.0" y="0.0" width="600" height="160"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="240"/>
</imageView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<constraints>
<constraint firstAttribute="trailing" secondItem="m9D-ne-YCP" secondAttribute="trailing" id="CWx-cc-UNX"/>
@@ -57,27 +60,27 @@
<constraint firstItem="m9D-ne-YCP" firstAttribute="leading" secondItem="PWv-9R-TGh" secondAttribute="leading" id="kKT-hw-BrG"/>
<constraint firstAttribute="bottom" secondItem="m9D-ne-YCP" secondAttribute="bottom" id="lvQ-hr-UgB"/>
</constraints>
<size key="customSize" width="600" height="160"/>
<size key="customSize" width="375" height="240"/>
<connections>
<outlet property="imageView" destination="m9D-ne-YCP" id="c9f-Gz-ruC"/>
</connections>
</collectionViewCell>
</cells>
</collectionView>
<view alpha="0.5" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="cWs-n0-Daa">
<rect key="frame" x="0.0" y="103" width="600" height="37"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<view userInteractionEnabled="NO" alpha="0.5" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="cWs-n0-Daa">
<rect key="frame" x="0.0" y="182.5" width="375" height="37"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="37" id="Jfa-Ja-OcD"/>
</constraints>
</view>
<pageControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" numberOfPages="3" translatesAutoresizingMaskIntoConstraints="NO" id="TnJ-eK-8qD">
<rect key="frame" x="0.0" y="103" width="600" height="37"/>
<pageControl opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" numberOfPages="3" translatesAutoresizingMaskIntoConstraints="NO" id="TnJ-eK-8qD">
<rect key="frame" x="0.0" y="182.5" width="375" height="37"/>
<constraints>
<constraint firstAttribute="height" constant="37" id="iLI-sf-nVD"/>
</constraints>
<color key="pageIndicatorTintColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="currentPageIndicatorTintColor" red="0.75686274509999996" green="0.1960784314" blue="0.15686274510000001" alpha="1" colorSpace="calibratedRGB"/>
<color key="pageIndicatorTintColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="currentPageIndicatorTintColor" red="0.75686274509999996" green="0.1960784314" blue="0.15686274510000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</pageControl>
</subviews>
<constraints>
@@ -99,16 +102,16 @@
<outlet property="pageControl" destination="TnJ-eK-8qD" id="APk-sp-T8S"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Infinite2TableViewCell" rowHeight="101" id="Pbe-Q2-B3O" customClass="Infinite2TableViewCell" customModule="Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="189" width="600" height="101"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Infinite2TableViewCell" rowHeight="120" id="Pbe-Q2-B3O" customClass="Infinite2TableViewCell" customModule="Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="268" width="375" height="120"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Pbe-Q2-B3O" id="Vro-Kf-tWq">
<rect key="frame" x="0.0" y="0.0" width="600" height="100"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="119"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="ba3-za-Kdk" customClass="InfiniteCollectionView" customModule="InfiniteCollectionView">
<rect key="frame" x="0.0" y="0.0" width="600" height="100"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="119.5"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" minimumLineSpacing="10" minimumInteritemSpacing="10" id="9h8-PU-jeW">
<size key="itemSize" width="100" height="100"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
@@ -117,12 +120,11 @@
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="ImageCollectionViewCell" id="HBK-Vd-0rJ" customClass="ImageCollectionViewCell" customModule="Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="100" height="100"/>
<rect key="frame" x="0.0" y="10" width="100" height="100"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="100" height="100"/>
<autoresizingMask key="autoresizingMask"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
</collectionViewCell>
</cells>
@@ -142,7 +144,7 @@
</prototypes>
</tableView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="aif-qL-b6r" firstAttribute="top" secondItem="blK-sK-Rl8" secondAttribute="bottom" id="BCF-CI-ZhI"/>
<constraint firstItem="blK-sK-Rl8" firstAttribute="leading" secondItem="hwa-cs-SAI" secondAttribute="leading" id="fCJ-oD-DRh"/>
@@ -156,7 +158,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="SUZ-hf-A1r" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="755" y="542"/>
<point key="canvasLocation" x="-489" y="157"/>
</scene>
</scenes>
</document>
+62 -48
View File
@@ -10,69 +10,70 @@ import UIKit
import InfiniteCollectionView
final class Pattern2ViewController: UIViewController {
static func createFromStoryboard() -> Pattern2ViewController {
let storyboard = UIStoryboard(name: "Pattern2", bundle: nil)
return storyboard.instantiateInitialViewController() as! Pattern2ViewController
}
@IBOutlet weak var tableView: UITableView! {
didSet {
tableView.delegate = self
tableView.dataSource = self
tableView.separatorStyle = .None
tableView.separatorStyle = .none
}
}
}
// MARK: - UITableViewDataSource, UITableViewDelegate
extension Pattern2ViewController: UITableViewDataSource, UITableViewDelegate {
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return 1
} else if section == 1 {
return 1
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0, 1: return 1
default: return 0
}
return 0
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCellWithIdentifier(InfiniteTableViewCell.identifier) as! InfiniteTableViewCell
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: InfiniteTableViewCell.identifier) as! InfiniteTableViewCell
return cell
} else if indexPath.section == 1 {
let cell = tableView.dequeueReusableCellWithIdentifier(Infinite2TableViewCell.identifier) as! Infinite2TableViewCell
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: Infinite2TableViewCell.identifier) as! Infinite2TableViewCell
return cell
} else {
default:
return UITableViewCell()
}
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.section == 0 {
return 240
} else if indexPath.section == 1 {
return 120
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch indexPath.section {
case 0: return 240
case 1: return 120
default: return 0
}
return 0
}
}
final class InfiniteTableViewCell: UITableViewCell {
static let identifier = "InfiniteTableViewCell"
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
NotificationCenter.default.addObserver(self, selector: #selector(InfiniteTableViewCell.rotate(_:)), name: .UIDeviceOrientationDidChange, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self, name: .UIDeviceOrientationDidChange, object: nil)
}
@IBOutlet weak var collectionView: InfiniteCollectionView! {
didSet {
collectionView.infiniteDataSource = self
collectionView.infiniteDelegate = self
collectionView.cellWidth = UIScreen.mainScreen().bounds.width
collectionView.registerNib(ImageCollectionViewCell.nib, forCellWithReuseIdentifier: ImageCollectionViewCell.identifier)
collectionView.register(ImageCollectionViewCell.nib, forCellWithReuseIdentifier: ImageCollectionViewCell.identifier)
}
}
@IBOutlet weak var layout: UICollectionViewFlowLayout! {
didSet {
layout.itemSize = CGSize(width: UIScreen.mainScreen().bounds.width, height: 239)
layout.itemSize = CGSize(width: UIScreen.main.bounds.width, height: 239)
}
}
@IBOutlet weak var pageControl: UIPageControl! {
@@ -80,53 +81,66 @@ final class InfiniteTableViewCell: UITableViewCell {
pageControl.numberOfPages = 4
}
}
func rotate(_ notification: Notification) {
let size = CGSize(width: UIScreen.main.bounds.width, height: 239)
layout.itemSize = size
layout.invalidateLayout()
collectionView.rotate(notification)
collectionView.layoutIfNeeded()
collectionView.setNeedsLayout()
}
}
// MARK: - InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate
extension InfiniteTableViewCell: InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate {
func numberOfItems(collectionView: UICollectionView) -> Int {
func number(ofItems collectionView: UICollectionView) -> Int {
return 4
}
func cellForItemAtIndexPath(collectionView: UICollectionView, dequeueIndexPath: NSIndexPath, indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(ImageCollectionViewCell.identifier, forIndexPath: dequeueIndexPath) as! ImageCollectionViewCell
cell.configure(dequeueIndexPath: indexPath)
func collectionView(_ collectionView: UICollectionView, dequeueForItemAt dequeueIndexPath: IndexPath, cellForItemAt usableIndexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ImageCollectionViewCell.identifier, for: dequeueIndexPath) as! ImageCollectionViewCell
cell.configure(indexPath: usableIndexPath)
return cell
}
func didSelectCellAtIndexPath(collectionView: UICollectionView, indexPath: NSIndexPath) {
}
func didUpdatePageIndex(index: Int) {
pageControl.currentPage = index
func scrollView(_ scrollView: UIScrollView, pageIndex: Int) {
pageControl.currentPage = pageIndex
}
}
final class Infinite2TableViewCell: UITableViewCell {
static let identifier = "Infinite2TableViewCell"
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
NotificationCenter.default.addObserver(self, selector: #selector(Infinite2TableViewCell.rotate(_:)), name: .UIDeviceOrientationDidChange, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self, name: .UIDeviceOrientationDidChange, object: nil)
}
@IBOutlet weak var collectionView: InfiniteCollectionView! {
didSet {
collectionView.infiniteDataSource = self
collectionView.infiniteDelegate = self
collectionView.cellWidth = 100
collectionView.registerNib(ImageCollectionViewCell.nib, forCellWithReuseIdentifier: ImageCollectionViewCell.identifier)
collectionView.register(ImageCollectionViewCell.nib, forCellWithReuseIdentifier: ImageCollectionViewCell.identifier)
}
}
}
// MARK: - InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate
extension Infinite2TableViewCell: InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate {
func numberOfItems(collectionView: UICollectionView) -> Int {
func number(ofItems collectionView: UICollectionView) -> Int {
return 10
}
func cellForItemAtIndexPath(collectionView: UICollectionView, dequeueIndexPath: NSIndexPath, indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(ImageCollectionViewCell.identifier, forIndexPath: dequeueIndexPath) as! ImageCollectionViewCell
cell.configure(dequeueIndexPath: indexPath)
func collectionView(_ collectionView: UICollectionView, dequeueForItemAt dequeueIndexPath: IndexPath, cellForItemAt usableIndexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ImageCollectionViewCell.identifier, for: dequeueIndexPath) as! ImageCollectionViewCell
cell.configure(indexPath: usableIndexPath)
return cell
}
func infiniteCollectionView(_ collectionView: UICollectionView, didSelectItemAt usableIndexPath: IndexPath) {
print("didSelectItemAt: \(usableIndexPath.item)")
}
func rotate(_ notification: Notification) {
collectionView.collectionViewLayout.invalidateLayout()
collectionView.rotate(notification)
collectionView.layoutIfNeeded()
collectionView.setNeedsLayout()
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "InfiniteCollectionView"
s.version = "1.0.4"
s.version = "1.3.1"
s.summary = "Infinite Scrolling Using UICollectionView."
s.homepage = "https://github.com/hryk224/InfiniteCollectionView"
s.screenshots = "https://github.com/hryk224/InfiniteCollectionView/wiki/images/sample1.gif"
@@ -8,7 +8,7 @@ Pod::Spec.new do |s|
s.author = { "hyyk224" => "hryk224@gmail.com" }
s.platform = :ios, "8.0"
s.source = { :git => "https://github.com/hryk224/InfiniteCollectionView.git", :tag => "#{s.version}" }
s.source_files = "InfiniteCollectionView/*.{h,swift}"
s.source_files = "Sources/*.{h,swift}"
s.frameworks = "UIKit"
s.requires_arc = true
end
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.4</string>
<string>1.3.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
+111 -176
View File
@@ -7,21 +7,20 @@
objects = {
/* Begin PBXBuildFile section */
935BD7281CE2702D00E5FDF7 /* InfiniteCollectionView.h in Headers */ = {isa = PBXBuildFile; fileRef = 935BD7261CE2702D00E5FDF7 /* InfiniteCollectionView.h */; settings = {ATTRIBUTES = (Public, ); }; };
935BD7291CE2702D00E5FDF7 /* InfiniteCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935BD7271CE2702D00E5FDF7 /* InfiniteCollectionView.swift */; };
OBJ_22 /* InfiniteCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_9 /* InfiniteCollectionView.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
935BD7001CE26F3B00E5FDF7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
935BD70D1CE26F8E00E5FDF7 /* InfiniteCollectionView.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = InfiniteCollectionView.framework; sourceTree = BUILT_PRODUCTS_DIR; };
935BD7261CE2702D00E5FDF7 /* InfiniteCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InfiniteCollectionView.h; sourceTree = "<group>"; };
935BD7271CE2702D00E5FDF7 /* InfiniteCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InfiniteCollectionView.swift; sourceTree = "<group>"; };
93CB2E361E563B85000DC0C1 /* InfiniteCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InfiniteCollectionView.h; sourceTree = "<group>"; };
OBJ_15 /* InfiniteCollectionView.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = InfiniteCollectionView.framework; sourceTree = BUILT_PRODUCTS_DIR; };
OBJ_6 /* Package.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
OBJ_9 /* InfiniteCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfiniteCollectionView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
935BD7091CE26F8E00E5FDF7 /* Frameworks */ = {
OBJ_23 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
buildActionMask = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
@@ -29,54 +28,50 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
935BD6E81CE26F3B00E5FDF7 = {
OBJ_14 /* Products */ = {
isa = PBXGroup;
children = (
935BD6F31CE26F3B00E5FDF7 /* InfiniteCollectionView */,
935BD6F21CE26F3B00E5FDF7 /* Products */,
);
sourceTree = "<group>";
};
935BD6F21CE26F3B00E5FDF7 /* Products */ = {
isa = PBXGroup;
children = (
935BD70D1CE26F8E00E5FDF7 /* InfiniteCollectionView.framework */,
OBJ_15 /* InfiniteCollectionView.framework */,
);
name = Products;
sourceTree = "<group>";
sourceTree = BUILT_PRODUCTS_DIR;
};
935BD6F31CE26F3B00E5FDF7 /* InfiniteCollectionView */ = {
OBJ_5 = {
isa = PBXGroup;
children = (
935BD7261CE2702D00E5FDF7 /* InfiniteCollectionView.h */,
935BD7271CE2702D00E5FDF7 /* InfiniteCollectionView.swift */,
935BD7001CE26F3B00E5FDF7 /* Info.plist */,
OBJ_6 /* Package.swift */,
OBJ_7 /* Sources */,
OBJ_14 /* Products */,
);
path = InfiniteCollectionView;
sourceTree = "<group>";
};
OBJ_7 /* Sources */ = {
isa = PBXGroup;
children = (
OBJ_8 /* InfiniteCollectionView */,
);
path = Sources;
sourceTree = "<group>";
};
OBJ_8 /* InfiniteCollectionView */ = {
isa = PBXGroup;
children = (
OBJ_9 /* InfiniteCollectionView.swift */,
93CB2E361E563B85000DC0C1 /* InfiniteCollectionView.h */,
);
name = InfiniteCollectionView;
path = Sources;
sourceTree = SOURCE_ROOT;
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
935BD70A1CE26F8E00E5FDF7 /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
935BD7281CE2702D00E5FDF7 /* InfiniteCollectionView.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */
935BD70C1CE26F8E00E5FDF7 /* InfiniteCollectionView */ = {
OBJ_17 /* InfiniteCollectionView */ = {
isa = PBXNativeTarget;
buildConfigurationList = 935BD7121CE26F8E00E5FDF7 /* Build configuration list for PBXNativeTarget "InfiniteCollectionView" */;
buildConfigurationList = OBJ_18 /* Build configuration list for PBXNativeTarget "InfiniteCollectionView" */;
buildPhases = (
935BD7081CE26F8E00E5FDF7 /* Sources */,
935BD7091CE26F8E00E5FDF7 /* Frameworks */,
935BD70A1CE26F8E00E5FDF7 /* Headers */,
935BD70B1CE26F8E00E5FDF7 /* Resources */,
OBJ_21 /* Sources */,
OBJ_23 /* Frameworks */,
);
buildRules = (
);
@@ -84,212 +79,152 @@
);
name = InfiniteCollectionView;
productName = InfiniteCollectionView;
productReference = 935BD70D1CE26F8E00E5FDF7 /* InfiniteCollectionView.framework */;
productReference = OBJ_15 /* InfiniteCollectionView.framework */;
productType = "com.apple.product-type.framework";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
935BD6E91CE26F3B00E5FDF7 /* Project object */ = {
OBJ_1 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = "hiroyuki yoshida";
TargetAttributes = {
935BD70C1CE26F8E00E5FDF7 = {
CreatedOnToolsVersion = 7.3.1;
};
};
LastUpgradeCheck = 9999;
};
buildConfigurationList = 935BD6EC1CE26F3B00E5FDF7 /* Build configuration list for PBXProject "InfiniteCollectionView" */;
buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "InfiniteCollectionView" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 935BD6E81CE26F3B00E5FDF7;
productRefGroup = 935BD6F21CE26F3B00E5FDF7 /* Products */;
mainGroup = OBJ_5;
productRefGroup = OBJ_14 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
935BD70C1CE26F8E00E5FDF7 /* InfiniteCollectionView */,
OBJ_17 /* InfiniteCollectionView */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
935BD70B1CE26F8E00E5FDF7 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
935BD7081CE26F8E00E5FDF7 /* Sources */ = {
OBJ_21 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
buildActionMask = 0;
files = (
935BD7291CE2702D00E5FDF7 /* InfiniteCollectionView.swift in Sources */,
OBJ_22 /* InfiniteCollectionView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
935BD7011CE26F3B00E5FDF7 /* Debug */ = {
OBJ_19 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = InfiniteCollectionView.xcodeproj/InfiniteCollectionView_Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = InfiniteCollectionView;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
TARGET_NAME = InfiniteCollectionView;
};
name = Debug;
};
935BD7021CE26F3B00E5FDF7 /* Release */ = {
OBJ_20 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = InfiniteCollectionView.xcodeproj/InfiniteCollectionView_Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = InfiniteCollectionView;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
TARGET_NAME = InfiniteCollectionView;
};
name = Release;
};
935BD7131CE26F8E00E5FDF7 /* Debug */ = {
OBJ_3 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = InfiniteCollectionView/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.github.hryk224.InfiniteCollectionView;
ENABLE_NS_ASSERTIONS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.10;
ONLY_ACTIVE_ARCH = YES;
OTHER_SWIFT_FLAGS = "-DXcode";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
SWIFT_VERSION = 3.0;
USE_HEADERMAP = NO;
};
name = Debug;
};
935BD7141CE26F8E00E5FDF7 /* Release */ = {
OBJ_4 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = InfiniteCollectionView/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.github.hryk224.InfiniteCollectionView;
GCC_OPTIMIZATION_LEVEL = s;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.10;
OTHER_SWIFT_FLAGS = "-DXcode";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 3.0;
USE_HEADERMAP = NO;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
935BD6EC1CE26F3B00E5FDF7 /* Build configuration list for PBXProject "InfiniteCollectionView" */ = {
OBJ_18 /* Build configuration list for PBXNativeTarget "InfiniteCollectionView" */ = {
isa = XCConfigurationList;
buildConfigurations = (
935BD7011CE26F3B00E5FDF7 /* Debug */,
935BD7021CE26F3B00E5FDF7 /* Release */,
OBJ_19 /* Debug */,
OBJ_20 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
defaultConfigurationName = Debug;
};
935BD7121CE26F8E00E5FDF7 /* Build configuration list for PBXNativeTarget "InfiniteCollectionView" */ = {
OBJ_2 /* Build configuration list for PBXProject "InfiniteCollectionView" */ = {
isa = XCConfigurationList;
buildConfigurations = (
935BD7131CE26F8E00E5FDF7 /* Debug */,
935BD7141CE26F8E00E5FDF7 /* Release */,
OBJ_3 /* Debug */,
OBJ_4 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
defaultConfigurationName = Debug;
};
/* End XCConfigurationList section */
};
rootObject = 935BD6E91CE26F3B00E5FDF7 /* Project object */;
rootObject = OBJ_1 /* Project object */;
}
@@ -2,6 +2,6 @@
<Workspace
version = "1.0">
<FileRef
location = "self:InfiniteCollectionView.xcodeproj">
location = "self:">
</FileRef>
</Workspace>
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "9999"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "OBJ_17"
BuildableName = "InfiniteCollectionView.framework"
BlueprintName = "InfiniteCollectionView"
ReferencedContainer = "container:InfiniteCollectionView.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "OBJ_24"
BuildableName = "InfiniteCollectionViewTests.xctest"
BlueprintName = "InfiniteCollectionViewTests"
ReferencedContainer = "container:InfiniteCollectionView.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "OBJ_17"
BuildableName = "InfiniteCollectionView.framework"
BlueprintName = "InfiniteCollectionView"
ReferencedContainer = "container:InfiniteCollectionView.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>InfiniteCollectionView.xcscheme</key>
<dict></dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict></dict>
</dict>
</plist>
@@ -1,124 +0,0 @@
//
// InfiniteCollectionView.swift
// Pods
//
// Created by hryk224 on 2015/10/17.
//
//
import UIKit
public protocol InfiniteCollectionViewDataSource: class {
func cellForItemAtIndexPath(collectionView: UICollectionView, dequeueIndexPath: NSIndexPath, indexPath: NSIndexPath) -> UICollectionViewCell
func numberOfItems(collectionView: UICollectionView) -> Int
}
@objc public protocol InfiniteCollectionViewDelegate: class {
optional func didSelectCellAtIndexPath(collectionView: UICollectionView, indexPath: NSIndexPath)
optional func didUpdatePageIndex(index: Int)
}
public class InfiniteCollectionView: UICollectionView {
private typealias Me = InfiniteCollectionView
private static let dummyCount: Int = 3
private static let defaultIdentifier = "Cell"
public weak var infiniteDataSource: InfiniteCollectionViewDataSource?
public weak var infiniteDelegate: InfiniteCollectionViewDelegate?
public var cellWidth: CGFloat = UIScreen.mainScreen().bounds.width
private var indexOffset: Int = 0
private var currentIndex: Int = 0
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
configure()
}
override public init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
configure()
}
}
// MARK: - private
private extension InfiniteCollectionView {
func configure() {
delegate = self
dataSource = self
registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: Me.defaultIdentifier)
}
func centerIfNeeded(scrollView: UIScrollView) {
let currentOffset = contentOffset
let contentWidth = totalContentWidth()
// Calculate the centre of content X position offset and the current distance from that centre point
let centerOffsetX: CGFloat = (CGFloat(Me.dummyCount) * contentWidth - bounds.size.width) / 2
let distFromCentre = centerOffsetX - currentOffset.x
if fabs(distFromCentre) > (contentWidth / 4) {
// Total cells (including partial cells) from centre
let cellcount = distFromCentre / cellWidth
// Amount of cells to shift (whole number) - conditional statement due to nature of +ve or -ve cellcount
let shiftCells = Int((cellcount > 0) ? floor(cellcount) : ceil(cellcount))
// Amount left over to correct for
let offsetCorrection = (abs(cellcount) % 1) * cellWidth
// Scroll back to the centre of the view, offset by the correction to ensure it's not noticable
if centerOffsetX > contentOffset.x {
//left scrolling
contentOffset = CGPoint(x: centerOffsetX - offsetCorrection, y: currentOffset.y)
} else if contentOffset.x > centerOffsetX {
//right scrolling
contentOffset = CGPoint(x: centerOffsetX + offsetCorrection, y: currentOffset.y)
}
// Make content shift as per shiftCells
shiftContentArray(correctedIndex(shiftCells))
reloadData()
}
let centerPoint = CGPoint(x: scrollView.frame.size.width / 2 + scrollView.contentOffset.x, y: scrollView.frame.size.height / 2 + scrollView.contentOffset.y)
guard let indexPath = indexPathForItemAtPoint(centerPoint) else { return }
infiniteDelegate?.didUpdatePageIndex?(correctedIndex(indexPath.item - indexOffset))
}
func shiftContentArray(offset: Int) {
indexOffset += offset
}
func totalContentWidth() -> CGFloat {
let numberOfCells = infiniteDataSource?.numberOfItems(self) ?? 0
return CGFloat(numberOfCells) * cellWidth
}
func correctedIndex(indexToCorrect: Int) -> Int {
if let numberOfItems = infiniteDataSource?.numberOfItems(self) {
if numberOfItems > indexToCorrect && indexToCorrect >= 0 {
return indexToCorrect
} else {
let countInIndex = Float(indexToCorrect) / Float(numberOfItems)
let flooredValue = Int(floor(countInIndex))
let offset = numberOfItems * flooredValue
return indexToCorrect - offset
}
} else {
return 0
}
}
}
// MARK: - UICollectionViewDataSource
extension InfiniteCollectionView: UICollectionViewDataSource {
public func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
let numberOfItems = infiniteDataSource?.numberOfItems(self) ?? 0
return Me.dummyCount * numberOfItems
}
public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var maybeCell: UICollectionViewCell!
maybeCell = infiniteDataSource?.cellForItemAtIndexPath(self, dequeueIndexPath: indexPath, indexPath: NSIndexPath(forRow: correctedIndex(indexPath.item - indexOffset), inSection: 0))
if maybeCell == nil {
maybeCell = collectionView.dequeueReusableCellWithReuseIdentifier(Me.defaultIdentifier, forIndexPath: indexPath)
}
return maybeCell
}
}
// MARK: - UICollectionViewDelegate
extension InfiniteCollectionView: UICollectionViewDelegate {
public func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
infiniteDelegate?.didSelectCellAtIndexPath?(self, indexPath: NSIndexPath(forRow: correctedIndex(indexPath.item - indexOffset), inSection: 0))
}
public func scrollViewDidScroll(scrollView: UIScrollView) {
centerIfNeeded(scrollView)
}
}
+9
View File
@@ -0,0 +1,9 @@
import PackageDescription
let package = Package(
name: "InfiniteCollectionView",
targets: [],
dependencies: [
.Package(url: "https://github.com/hryk224/InfiniteCollectionView", majorVersion: 1),
]
)
+7 -7
View File
@@ -3,14 +3,15 @@
Infinite horizontal scrolling using `UICollectionView`
[![CocoaPods Compatible](http://img.shields.io/cocoapods/v/InfiniteCollectionView.svg?style=flat)](http://cocoadocs.org/docsets/InfiniteCollectionView)
[![Swift 2.0](https://img.shields.io/badge/Swift-2.0-orange.svg?style=flat)](https://developer.apple.com/swift/)
[![Swift 3.0](https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat)](https://developer.apple.com/swift/)
<img src="https://github.com/hryk224/InfiniteCollectionView/wiki/images/sample1.gif" width="320" >
<img src="https://github.com/hryk224/InfiniteCollectionView/wiki/images/sample2.gif" width="320" >
## Requirements
- iOS 8.0+
- Swift 2.0+
- Swift 3.0+
- ARC
## install
@@ -43,17 +44,16 @@ import InfiniteCollectionView
```Swift
collectionView.infiniteDataSource = XXX
collectionView.infiniteDelegate = XXX
collectionView.cellWidth = XXX
```
```Swift
// protocol
func cellForItemAtIndexPath(collectionView: UICollectionView, dequeueIndexPath: NSIndexPath, indexPath: NSIndexPath) -> UICollectionViewCell
func numberOfItems(collectionView: UICollectionView) -> Int
func number(ofItems collectionView: UICollectionView) -> Int
func collectionView(_ collectionView: UICollectionView, dequeueForItemAt dequeueIndexPath: IndexPath, cellForItemAt usableIndexPath: IndexPath) -> UICollectionViewCell
// optional
func didSelectCellAtIndexPath(collectionView: UICollectionView, indexPath: NSIndexPath)
func didUpdatePageIndex(index: Int)
func infiniteCollectionView(_ collectionView: UICollectionView, didSelectItemAt usableIndexPath: IndexPath)
func scrollView(_ scrollView: UIScrollView, pageIndex: Int)
```
## Photos from
+151
View File
@@ -0,0 +1,151 @@
//
// InfiniteCollectionView.swift
// Pods
//
// Created by hryk224 on 2015/10/17.
//
//
import UIKit
@objc public protocol InfiniteCollectionViewDataSource: class {
@objc @available(*, deprecated, renamed: "number(ofItems:)")
optional func numberOfItems(collectionView: UICollectionView) -> Int
@objc @available(*, deprecated, renamed: "collectionView(_:dequeueForItemAt:cellForItemAt:)")
optional func cellForItemAtIndexPath(collectionView: UICollectionView, dequeueIndexPath: NSIndexPath, indexPath: NSIndexPath) -> UICollectionViewCell
func number(ofItems collectionView: UICollectionView) -> Int
func collectionView(_ collectionView: UICollectionView, dequeueForItemAt dequeueIndexPath: IndexPath, cellForItemAt usableIndexPath: IndexPath) -> UICollectionViewCell
}
@objc public protocol InfiniteCollectionViewDelegate: class {
@objc @available(*, deprecated, renamed: "infiniteCollectionView(_:didSelectItemAt:)")
optional func didSelectCellAtIndexPath(collectionView: UICollectionView, indexPath: NSIndexPath)
@objc @available(*, deprecated, renamed: "scrollView(_:pageIndex:)")
optional func didUpdatePageIndex(index: Int)
@objc optional func infiniteCollectionView(_ collectionView: UICollectionView, didSelectItemAt usableIndexPath: IndexPath)
@objc optional func scrollView(_ scrollView: UIScrollView, pageIndex: Int)
}
open class InfiniteCollectionView: UICollectionView {
fileprivate typealias Me = InfiniteCollectionView
fileprivate static let dummyCount: Int = 3
fileprivate static let defaultIdentifier = "Cell"
open weak var infiniteDataSource: InfiniteCollectionViewDataSource?
open weak var infiniteDelegate: InfiniteCollectionViewDelegate?
fileprivate var indexOffset: Int = 0
fileprivate var pageIndex = 0
@available(*, deprecated, message: "It becomes unnecessary because it uses UICollectionViewFlowLayout.")
open var cellWidth: CGFloat?
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
configure()
}
override public init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
configure()
}
deinit {
NotificationCenter.default.removeObserver(self, name: .UIDeviceOrientationDidChange, object: nil)
}
open func rotate(_ notification: Notification) {
setContentOffset(CGPoint(x: CGFloat(pageIndex + indexOffset) * itemWidth, y: contentOffset.y), animated: false)
}
open override func selectItem(at indexPath: IndexPath?, animated: Bool, scrollPosition: UICollectionViewScrollPosition) {
// Correct the input IndexPath
let correctedIndexPath = IndexPath(row: correctedIndex(indexPath!.item + indexOffset), section: 0);
// Get the currently visible cell(s) - assumes a cell is visible
guard let visibleCell = self.visibleCells.first else{
return; // Nothing to select...
}
// Index path of the cell - does not consider multiple cells on the screen at the same time
var visibleIndexPath : IndexPath! = self.indexPath(for: visibleCell);
let testIndexPath = IndexPath(row: correctedIndex(visibleIndexPath!.item), section: 0);
guard correctedIndexPath != testIndexPath else{
return; // Do not re-select the same cell
}
// Call supercase to select the correct IndexPath
super.selectItem(at: correctedIndexPath, animated: animated, scrollPosition: scrollPosition);
}
}
// MARK: - private
private extension InfiniteCollectionView {
var itemWidth: CGFloat {
guard let layout = collectionViewLayout as? UICollectionViewFlowLayout else { return 0 }
return layout.itemSize.width + layout.minimumInteritemSpacing
}
var totalContentWidth: CGFloat {
let numberOfCells: CGFloat = CGFloat(infiniteDataSource?.number(ofItems: self) ?? 0)
return numberOfCells * itemWidth
}
func configure() {
delegate = self
dataSource = self
register(UICollectionViewCell.self, forCellWithReuseIdentifier: Me.defaultIdentifier)
NotificationCenter.default.addObserver(self, selector: #selector(InfiniteCollectionView.rotate(_:)), name: .UIDeviceOrientationDidChange, object: nil)
}
func centerIfNeeded(_ scrollView: UIScrollView) {
let currentOffset = contentOffset
let centerX = (scrollView.contentSize.width - bounds.width) / 2
let distFromCenter = centerX - currentOffset.x
if fabs(distFromCenter) > (totalContentWidth / 4) {
let cellcount = distFromCenter / itemWidth
let shiftCells = Int((cellcount > 0) ? floor(cellcount) : ceil(cellcount))
let offsetCorrection = (abs(cellcount).truncatingRemainder(dividingBy: 1)) * itemWidth
if centerX > contentOffset.x {
contentOffset = CGPoint(x: centerX - offsetCorrection, y: currentOffset.y)
} else {
contentOffset = CGPoint(x: centerX + offsetCorrection, y: currentOffset.y)
}
shiftContentArray(correctedIndex(shiftCells))
reloadData()
}
let centerPoint = CGPoint(x: scrollView.frame.size.width / 2 + scrollView.contentOffset.x, y: scrollView.frame.size.height / 2 + scrollView.contentOffset.y)
guard let indexPath = indexPathForItem(at: centerPoint) else { return }
pageIndex = correctedIndex(indexPath.item - indexOffset)
infiniteDelegate?.scrollView?(scrollView, pageIndex: pageIndex)
}
func shiftContentArray(_ offset: Int) {
indexOffset += offset
}
func correctedIndex(_ indexToCorrect: Int) -> Int {
guard let numberOfItems = infiniteDataSource?.number(ofItems: self) else { return 0 }
if numberOfItems > indexToCorrect && indexToCorrect >= 0 {
return indexToCorrect
}
let countInIndex = Float(indexToCorrect) / Float(numberOfItems)
let flooredValue = Int(floor(countInIndex))
let offset = numberOfItems * flooredValue
return indexToCorrect - offset
}
}
// MARK: - UICollectionViewDataSource
extension InfiniteCollectionView: UICollectionViewDataSource {
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
let numberOfItems = infiniteDataSource?.number(ofItems: collectionView) ?? 0
return Me.dummyCount * numberOfItems
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let maybeCell = infiniteDataSource?.collectionView(collectionView, dequeueForItemAt: indexPath, cellForItemAt: IndexPath(item: correctedIndex(indexPath.item - indexOffset), section: 0)) {
return maybeCell
}
return collectionView.dequeueReusableCell(withReuseIdentifier: Me.defaultIdentifier, for: indexPath)
}
}
// MARK: - UICollectionViewDelegate
extension InfiniteCollectionView: UICollectionViewDelegate {
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
infiniteDelegate?.infiniteCollectionView?(collectionView, didSelectItemAt: IndexPath(item: correctedIndex(indexPath.item - indexOffset), section: 0))
}
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
centerIfNeeded(scrollView)
}
}