Repository: ltebean/LTInfiniteScrollView-Swift Branch: master Commit: 80bb05704e5f Files: 14 Total size: 35.6 KB Directory structure: gitextract_c61js3h3/ ├── .gitignore ├── .swift-version ├── LICENSE ├── LTInfiniteScrollView-Swift/ │ ├── AppDelegate.swift │ ├── Assets.xcassets/ │ │ └── AppIcon.appiconset/ │ │ └── Contents.json │ ├── Base.lproj/ │ │ └── Main.storyboard │ ├── Info.plist │ ├── Lauch.storyboard │ ├── Sources/ │ │ └── LTInfiniteScrollView.swift │ └── ViewController.swift ├── LTInfiniteScrollView-Swift.xcodeproj/ │ ├── project.pbxproj │ └── project.xcworkspace/ │ └── contents.xcworkspacedata ├── LTInfiniteScrollViewSwift.podspec └── README.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ .DS_Store *.swp *~.nib Pods build/ xcuserdata/ *.pbxuser *.perspective *.perspectivev3 ================================================ FILE: .swift-version ================================================ 3.0 ================================================ FILE: LICENSE ================================================ Copyright © 2015 ltebean Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. (MIT License) ================================================ FILE: LTInfiniteScrollView-Swift/AppDelegate.swift ================================================ // // AppDelegate.swift // LTInfiniteScrollView-Swift // // Created by ltebean on 16/1/8. // Copyright © 2016年 io. All rights reserved. // import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } 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) { // 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) { // 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) { // 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) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } } ================================================ FILE: LTInfiniteScrollView-Swift/Assets.xcassets/AppIcon.appiconset/Contents.json ================================================ { "images" : [ { "idiom" : "iphone", "size" : "29x29", "scale" : "2x" }, { "idiom" : "iphone", "size" : "29x29", "scale" : "3x" }, { "idiom" : "iphone", "size" : "40x40", "scale" : "2x" }, { "idiom" : "iphone", "size" : "40x40", "scale" : "3x" }, { "idiom" : "iphone", "size" : "60x60", "scale" : "2x" }, { "idiom" : "iphone", "size" : "60x60", "scale" : "3x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: LTInfiniteScrollView-Swift/Base.lproj/Main.storyboard ================================================ ================================================ FILE: LTInfiniteScrollView-Swift/Info.plist ================================================ CFBundleDevelopmentRegion en CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType APPL CFBundleShortVersionString 1.0 CFBundleSignature ???? CFBundleVersion 1 LSRequiresIPhoneOS UILaunchStoryboardName Lauch UIMainStoryboardFile Main UIRequiredDeviceCapabilities armv7 UISupportedInterfaceOrientations UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight ================================================ FILE: LTInfiniteScrollView-Swift/Lauch.storyboard ================================================ ================================================ FILE: LTInfiniteScrollView-Swift/Sources/LTInfiniteScrollView.swift ================================================ // // LTInfiniteScrollView.swift // LTInfiniteScrollView-Swift // // Created by ltebean on 16/1/8. // Copyright © 2016年 io. All rights reserved. // import UIKit public protocol LTInfiniteScrollViewDelegate: class { func updateView(_ view: UIView, withProgress progress: CGFloat, scrollDirection direction: LTInfiniteScrollView.ScrollDirection) func scrollViewDidScrollToIndex(_ scrollView: LTInfiniteScrollView, index: Int) } public protocol LTInfiniteScrollViewDataSource: class { func viewAtIndex(_ index: Int, reusingView view: UIView?) -> UIView func numberOfViews() -> Int func numberOfVisibleViews() -> Int } open class LTInfiniteScrollView: UIView { public enum ScrollDirection { case previous case next } override public init(frame: CGRect) { super.init(frame: frame) self.setup() } required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) self.setup() } open var pagingEnabled = false { didSet { scrollView.isPagingEnabled = pagingEnabled } } open var bounces = false { didSet { scrollView.bounces = bounces } } open var contentInset = UIEdgeInsets.zero { didSet { scrollView.contentInset = contentInset; } } open var scrollEnabled = false { didSet { scrollView.isScrollEnabled = scrollEnabled } } open var maxScrollDistance: Int? open fileprivate(set) var currentIndex = 0 fileprivate var scrollView: UIScrollView! fileprivate var viewSize: CGSize! fileprivate var visibleViewCount = 0 fileprivate var totalViewCount = 0 fileprivate var preContentOffsetX: CGFloat = 0 fileprivate var totalWidth: CGFloat = 0 fileprivate var scrollDirection: ScrollDirection = .next fileprivate var views: [Int: UIView] = [:] open weak var delegate: LTInfiniteScrollViewDelegate? open var dataSource: LTInfiniteScrollViewDataSource! // MARK: public func open func reloadData(initialIndex: Int=0) { for view in scrollView.subviews { view.removeFromSuperview() } visibleViewCount = dataSource.numberOfVisibleViews() totalViewCount = dataSource.numberOfViews() updateContentSize() views = [:] currentIndex = initialIndex scrollView.contentOffset = contentOffsetForIndex(currentIndex) reArrangeViews() updateProgress() } open func scrollToIndex(_ index: Int, animated: Bool) { if index < currentIndex { scrollDirection = .previous } else { scrollDirection = .next } scrollView.setContentOffset(contentOffsetForIndex(index), animated: animated) } open func viewAtIndex(_ index: Int) -> UIView? { return views[index] } open func allViews() -> [UIView] { return [UIView](views.values) } open override func layoutSubviews() { let index = currentIndex; super.layoutSubviews() scrollView.frame = bounds updateContentSize() for (index, view) in views { view.center = self.centerForViewAtIndex(index) } scrollToIndex(index, animated: false) updateProgress() } // MARK: private func fileprivate func setup() { scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: self.bounds.width, height: self.bounds.height)) scrollView.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight] scrollView.showsHorizontalScrollIndicator = false scrollView.delegate = self scrollView.clipsToBounds = false addSubview(self.scrollView) } fileprivate func updateContentSize() { let viewWidth = bounds.width / CGFloat(visibleViewCount) let viewHeight: CGFloat = bounds.height viewSize = CGSize(width: viewWidth, height: viewHeight) totalWidth = viewWidth * CGFloat(totalViewCount) scrollView.contentSize = CGSize(width: self.totalWidth, height: self.bounds.height) } fileprivate func reArrangeViews() { var indexesNeeded = Set() let begin = currentIndex - Int(ceil(Double(visibleViewCount) / 2.0)) let end = currentIndex + Int(ceil(Double(visibleViewCount) / 2.0)) for i in begin...end { if i < 0 { let index = end - i if index < totalViewCount { indexesNeeded.insert(index) } } else if i >= totalViewCount { let index = begin - i if index >= 0 { indexesNeeded.insert(index) } } else { indexesNeeded.insert(i) } } for indexNeeded in indexesNeeded { var view = views[indexNeeded] if view != nil { continue } let currentIndexes = [Int](views.keys) for index in currentIndexes { if !indexesNeeded.contains(index) { view = views[index] views.removeValue(forKey: index) break } } let viewNeeded = dataSource.viewAtIndex(indexNeeded, reusingView: view) viewNeeded.removeFromSuperview() viewNeeded.tag = indexNeeded viewNeeded.center = self.centerForViewAtIndex(indexNeeded) views[indexNeeded] = viewNeeded scrollView.addSubview(viewNeeded) } } fileprivate func updateProgress() { guard let delegate = delegate else { return } let currentCenterX = currentCenter().x for view in allViews() { let progress = (view.center.x - currentCenterX) / bounds.width * CGFloat(visibleViewCount) delegate.updateView(view, withProgress: progress, scrollDirection: scrollDirection) } } // MARK: helper fileprivate func needsCenterPage() -> Bool { let offsetX = scrollView.contentOffset.x if offsetX < -scrollView.contentInset.left || offsetX > scrollView.contentSize.width - viewSize.width { return false } else { return true } } fileprivate func currentCenter() -> CGPoint { let x = scrollView.contentOffset.x + bounds.width / 2.0 let y = scrollView.contentOffset.y return CGPoint(x: x, y: y) } fileprivate func contentOffsetForIndex(_ index: Int) -> CGPoint { let centerX = centerForViewAtIndex(index).x var x: CGFloat = centerX - self.bounds.width / 2.0 x = max(-scrollView.contentInset.left, x) x = min(x, scrollView.contentSize.width) return CGPoint(x: x, y: 0) } fileprivate func centerForViewAtIndex(_ index: Int) -> CGPoint { let y = bounds.midY let x = CGFloat(index) * viewSize.width + viewSize.width / 2 return CGPoint(x: x, y: y) } fileprivate func didScrollToIndex(_ index : Int) { delegate?.scrollViewDidScrollToIndex(self, index: index) } } extension LTInfiniteScrollView: UIScrollViewDelegate { public func scrollViewDidScroll(_ scrollView: UIScrollView) { if viewSize == nil { return } let currentCenterX = currentCenter().x let offsetX = scrollView.contentOffset.x currentIndex = Int(round((currentCenterX - viewSize.width / 2) / viewSize.width)) if offsetX > preContentOffsetX { scrollDirection = .next } else { scrollDirection = .previous } preContentOffsetX = offsetX reArrangeViews() updateProgress() } public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { if !pagingEnabled && !decelerate && needsCenterPage() { let offsetX = scrollView.contentOffset.x if offsetX < 0 || offsetX > scrollView.contentSize.width { return } scrollView.setContentOffset(contentOffsetForIndex(currentIndex), animated: true) didScrollToIndex(currentIndex) } } public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { if !pagingEnabled && needsCenterPage() { scrollView.setContentOffset(contentOffsetForIndex(currentIndex), animated: true) } didScrollToIndex(currentIndex) } public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) { guard let maxScrollDistance = maxScrollDistance , maxScrollDistance > 0 else { return } guard needsCenterPage() else { return } let targetX = targetContentOffset.pointee.x let currentX = contentOffsetForIndex(currentIndex).x if fabs(targetX - currentX) <= viewSize.width / 2 { targetContentOffset.pointee.x = contentOffsetForIndex(currentIndex).x } else { let distance = maxScrollDistance - 1 var targetIndex = scrollDirection == .next ? currentIndex + distance : currentIndex - distance targetIndex = max(0, targetIndex) targetContentOffset.pointee.x = contentOffsetForIndex(targetIndex).x } } } ================================================ FILE: LTInfiniteScrollView-Swift/ViewController.swift ================================================ // // ViewController.swift // LTInfiniteScrollView-Swift // // Created by ltebean on 16/1/8. // Copyright © 2016年 io. All rights reserved. // import UIKit class ViewController: UIViewController { let screenWidth = UIScreen.main.bounds.size.width @IBOutlet weak var scrollView: LTInfiniteScrollView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. scrollView.dataSource = self scrollView.delegate = self scrollView.maxScrollDistance = 5 let size = screenWidth / CGFloat(numberOfVisibleViews()) scrollView.contentInset.left = screenWidth / 2 - size / 2 scrollView.contentInset.right = screenWidth / 2 - size / 2 view.addSubview(scrollView) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) scrollView.reloadData(initialIndex: 0) } } extension ViewController: LTInfiniteScrollViewDataSource { func viewAtIndex(_ index: Int, reusingView view: UIView?) -> UIView { if let label = view as? UILabel { label.text = "\(index)" return label } else { let size = screenWidth / CGFloat(numberOfVisibleViews()) let label = UILabel(frame: CGRect(x: 0, y: 0, width: size, height: size)) label.textAlignment = .center label.backgroundColor = UIColor.darkGray label.textColor = UIColor.white label.layer.cornerRadius = size / 2 label.layer.masksToBounds = true label.text = "\(index)" return label } } func numberOfViews() -> Int { return 10 } func numberOfVisibleViews() -> Int { return 5 } } extension ViewController: LTInfiniteScrollViewDelegate { func updateView(_ view: UIView, withProgress progress: CGFloat, scrollDirection direction: LTInfiniteScrollView.ScrollDirection) { let size = screenWidth / CGFloat(numberOfVisibleViews()) var transform = CGAffineTransform.identity // scale let scale = (1.4 - 0.3 * (fabs(progress))) transform = transform.scaledBy(x: scale, y: scale) // translate var translate = size / 4 * progress if progress > 1 { translate = size / 4 } else if progress < -1 { translate = -size / 4 } transform = transform.translatedBy(x: translate, y: 0) view.transform = transform } func scrollViewDidScrollToIndex(_ scrollView: LTInfiniteScrollView, index: Int) { print("scroll to index: \(index)") } } ================================================ FILE: LTInfiniteScrollView-Swift.xcodeproj/project.pbxproj ================================================ // !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 46; objects = { /* Begin PBXBuildFile section */ FA6635951C50BF8A00A12676 /* Lauch.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FA6635941C50BF8A00A12676 /* Lauch.storyboard */; }; FAA51EA41C3F7E9D00CD7F5A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA51EA31C3F7E9D00CD7F5A /* AppDelegate.swift */; }; FAA51EA61C3F7E9D00CD7F5A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA51EA51C3F7E9D00CD7F5A /* ViewController.swift */; }; FAA51EA91C3F7E9D00CD7F5A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FAA51EA71C3F7E9D00CD7F5A /* Main.storyboard */; }; FAA51EAB1C3F7E9D00CD7F5A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FAA51EAA1C3F7E9D00CD7F5A /* Assets.xcassets */; }; FAA51EB71C3F7EE400CD7F5A /* LTInfiniteScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA51EB61C3F7EE400CD7F5A /* LTInfiniteScrollView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ FA6635941C50BF8A00A12676 /* Lauch.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Lauch.storyboard; sourceTree = ""; }; FAA51EA01C3F7E9D00CD7F5A /* LTInfiniteScrollView-Swift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "LTInfiniteScrollView-Swift.app"; sourceTree = BUILT_PRODUCTS_DIR; }; FAA51EA31C3F7E9D00CD7F5A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; FAA51EA51C3F7E9D00CD7F5A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; FAA51EA81C3F7E9D00CD7F5A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; FAA51EAA1C3F7E9D00CD7F5A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; FAA51EAF1C3F7E9D00CD7F5A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; FAA51EB61C3F7EE400CD7F5A /* LTInfiniteScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LTInfiniteScrollView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ FAA51E9D1C3F7E9D00CD7F5A /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ FAA51E971C3F7E9D00CD7F5A = { isa = PBXGroup; children = ( FAA51EA21C3F7E9D00CD7F5A /* LTInfiniteScrollView-Swift */, FAA51EA11C3F7E9D00CD7F5A /* Products */, ); sourceTree = ""; }; FAA51EA11C3F7E9D00CD7F5A /* Products */ = { isa = PBXGroup; children = ( FAA51EA01C3F7E9D00CD7F5A /* LTInfiniteScrollView-Swift.app */, ); name = Products; sourceTree = ""; }; FAA51EA21C3F7E9D00CD7F5A /* LTInfiniteScrollView-Swift */ = { isa = PBXGroup; children = ( FAA51EB51C3F7EAA00CD7F5A /* Sources */, FAA51EA31C3F7E9D00CD7F5A /* AppDelegate.swift */, FAA51EA51C3F7E9D00CD7F5A /* ViewController.swift */, FAA51EA71C3F7E9D00CD7F5A /* Main.storyboard */, FA6635941C50BF8A00A12676 /* Lauch.storyboard */, FAA51EAA1C3F7E9D00CD7F5A /* Assets.xcassets */, FAA51EAF1C3F7E9D00CD7F5A /* Info.plist */, ); path = "LTInfiniteScrollView-Swift"; sourceTree = ""; }; FAA51EB51C3F7EAA00CD7F5A /* Sources */ = { isa = PBXGroup; children = ( FAA51EB61C3F7EE400CD7F5A /* LTInfiniteScrollView.swift */, ); path = Sources; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ FAA51E9F1C3F7E9D00CD7F5A /* LTInfiniteScrollView-Swift */ = { isa = PBXNativeTarget; buildConfigurationList = FAA51EB21C3F7E9D00CD7F5A /* Build configuration list for PBXNativeTarget "LTInfiniteScrollView-Swift" */; buildPhases = ( FAA51E9C1C3F7E9D00CD7F5A /* Sources */, FAA51E9D1C3F7E9D00CD7F5A /* Frameworks */, FAA51E9E1C3F7E9D00CD7F5A /* Resources */, ); buildRules = ( ); dependencies = ( ); name = "LTInfiniteScrollView-Swift"; productName = "LTInfiniteScrollView-Swift"; productReference = FAA51EA01C3F7E9D00CD7F5A /* LTInfiniteScrollView-Swift.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ FAA51E981C3F7E9D00CD7F5A /* Project object */ = { isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0710; LastUpgradeCheck = 0800; ORGANIZATIONNAME = io; TargetAttributes = { FAA51E9F1C3F7E9D00CD7F5A = { CreatedOnToolsVersion = 7.1; LastSwiftMigration = 0800; }; }; }; buildConfigurationList = FAA51E9B1C3F7E9D00CD7F5A /* Build configuration list for PBXProject "LTInfiniteScrollView-Swift" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( en, Base, ); mainGroup = FAA51E971C3F7E9D00CD7F5A; productRefGroup = FAA51EA11C3F7E9D00CD7F5A /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( FAA51E9F1C3F7E9D00CD7F5A /* LTInfiniteScrollView-Swift */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ FAA51E9E1C3F7E9D00CD7F5A /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( FAA51EAB1C3F7E9D00CD7F5A /* Assets.xcassets in Resources */, FA6635951C50BF8A00A12676 /* Lauch.storyboard in Resources */, FAA51EA91C3F7E9D00CD7F5A /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ FAA51E9C1C3F7E9D00CD7F5A /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( FAA51EB71C3F7EE400CD7F5A /* LTInfiniteScrollView.swift in Sources */, FAA51EA61C3F7E9D00CD7F5A /* ViewController.swift in Sources */, FAA51EA41C3F7E9D00CD7F5A /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ FAA51EA71C3F7E9D00CD7F5A /* Main.storyboard */ = { isa = PBXVariantGroup; children = ( FAA51EA81C3F7E9D00CD7F5A /* Base */, ); name = Main.storyboard; sourceTree = ""; }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ FAA51EB01C3F7E9D00CD7F5A /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; 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_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"; 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", "$(inherited)", ); 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.1; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; }; FAA51EB11C3F7E9D00CD7F5A /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; 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_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"; 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.1; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VALIDATE_PRODUCT = YES; }; name = Release; }; FAA51EB31C3F7E9D00CD7F5A /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = "LTInfiniteScrollView-Swift/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "ltebean.LTInfiniteScrollView-Swift"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 3.0; }; name = Debug; }; FAA51EB41C3F7E9D00CD7F5A /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = "LTInfiniteScrollView-Swift/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "ltebean.LTInfiniteScrollView-Swift"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 3.0; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ FAA51E9B1C3F7E9D00CD7F5A /* Build configuration list for PBXProject "LTInfiniteScrollView-Swift" */ = { isa = XCConfigurationList; buildConfigurations = ( FAA51EB01C3F7E9D00CD7F5A /* Debug */, FAA51EB11C3F7E9D00CD7F5A /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; FAA51EB21C3F7E9D00CD7F5A /* Build configuration list for PBXNativeTarget "LTInfiniteScrollView-Swift" */ = { isa = XCConfigurationList; buildConfigurations = ( FAA51EB31C3F7E9D00CD7F5A /* Debug */, FAA51EB41C3F7E9D00CD7F5A /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = FAA51E981C3F7E9D00CD7F5A /* Project object */; } ================================================ FILE: LTInfiniteScrollView-Swift.xcodeproj/project.xcworkspace/contents.xcworkspacedata ================================================ ================================================ FILE: LTInfiniteScrollViewSwift.podspec ================================================ Pod::Spec.new do |s| s.name = "LTInfiniteScrollViewSwift" s.version = "0.5.0" s.summary = "An infinite scrollview allowing easily applying animation" s.homepage = "https://github.com/ltebean/LTInfiniteScrollView-Swift" s.license = "MIT" s.author = { "ltebean" => "yucong1118@gmail.com" } s.source = { :git => "https://github.com/ltebean/LTInfiniteScrollView-Swift.git", :tag => 'v0.5.0'} s.source_files = "LTInfiniteScrollView-Swift/Sources/LTInfiniteScrollView.swift" s.requires_arc = true s.platform = :ios, '8.0' end ================================================ FILE: README.md ================================================ ![LTInfiniteScrollViewSwift](https://cocoapod-badges.herokuapp.com/v/LTInfiniteScrollViewSwift/badge.png) ## Demo ##### 1. You can apply animation to each view during the scroll: ![LTInfiniteScrollView](https://raw.githubusercontent.com/ltebean/LTInfiniteScrollView/master/demo/demo.gif) ##### 2. The iOS 9 task switcher animation can be implemented in ten minutes with the support of this lib: ![LTInfiniteScrollView](https://raw.githubusercontent.com/ltebean/LTInfiniteScrollView/master/demo/task-switcher-demo.gif) ##### 3. The fancy menu can also be implemented easily: ![LTInfiniteScrollView](https://raw.githubusercontent.com/ltebean/LTInfiniteScrollView/master/demo/menu-demo.gif) You can find the full demo in the Objective-C version: https://github.com/ltebean/LTInfiniteScrollView. ## Installation ``` pod 'LTInfiniteScrollViewSwift' ``` Or just copy `LTInfiniteScrollView.swift` into your project. ## Usage You can create the scroll view by: ```swift scrollView = LTInfiniteScrollView(frame: CGRect(x: 0, y: 200, width: screenWidth, height: 300)) scrollView.dataSource = self scrollView.delegate = self scrollView.maxScrollDistance = 5 scrollView.reloadData(initialIndex: 0) ``` Then implement `LTInfiniteScrollViewDataSource` protocol: ```swift public protocol LTInfiniteScrollViewDataSource: class { func viewAtIndex(index: Int, reusingView view: UIView?) -> UIView func numberOfViews() -> Int func numberOfVisibleViews() -> Int } ``` Sample code: ```swift func numberOfViews() -> Int { return 100 } func numberOfVisibleViews() -> Int { return 5 } func viewAtIndex(index: Int, reusingView view: UIView?) -> UIView { if let label = view as? UILabel { label.text = "\(index)" return label } else { let size = screenWidth / CGFloat(numberOfVisibleViews()) let label = UILabel(frame: CGRect(x: 0, y: 0, width: size, height: size)) label.textAlignment = .Center label.backgroundColor = UIColor.darkGrayColor() label.textColor = UIColor.whiteColor() label.layer.cornerRadius = size / 2 label.layer.masksToBounds = true label.text = "\(index)" return label } } ``` If you want to apply any animation during scrolling, implement `LTInfiniteScrollViewDelegate` protocol: ```swift public protocol LTInfiniteScrollViewDelegate: class { func updateView(view: UIView, withProgress progress: CGFloat, scrollDirection direction: ScrollDirection) } ``` The value of progress dependends on the position of that view, if there are 5 visible views, the value will be ranged from -2 to 2: ``` | | |-2 -1 0 1 2| | | ``` You can clone the project and investigate the example for details.