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
================================================
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="LTInfiniteScrollView_Swift" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yzD-Zb-f12" customClass="LTInfiniteScrollView" customModule="LTInfiniteScrollView_Swift" customModuleProvider="target">
<rect key="frame" x="0.0" y="220" width="320" height="128"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="128" id="Arm-FM-Q2S"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="yzD-Zb-f12" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="1cl-oU-8xe"/>
<constraint firstItem="yzD-Zb-f12" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="88N-GS-iDO"/>
<constraint firstAttribute="trailing" secondItem="yzD-Zb-f12" secondAttribute="trailing" id="grk-R4-pPJ"/>
</constraints>
</view>
<connections>
<outlet property="scrollView" destination="yzD-Zb-f12" id="2tL-BZ-Una"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="254" y="519"/>
</scene>
</scenes>
</document>
================================================
FILE: LTInfiniteScrollView-Swift/Info.plist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<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>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>Lauch</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
================================================
FILE: LTInfiniteScrollView-Swift/Lauch.storyboard
================================================
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
</dependencies>
<scenes/>
</document>
================================================
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<Int>()
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<CGPoint>) {
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 = "<group>"; };
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 = "<group>"; };
FAA51EA51C3F7E9D00CD7F5A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
FAA51EA81C3F7E9D00CD7F5A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
FAA51EAA1C3F7E9D00CD7F5A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
FAA51EAF1C3F7E9D00CD7F5A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
FAA51EB61C3F7EE400CD7F5A /* LTInfiniteScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LTInfiniteScrollView.swift; sourceTree = "<group>"; };
/* 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 = "<group>";
};
FAA51EA11C3F7E9D00CD7F5A /* Products */ = {
isa = PBXGroup;
children = (
FAA51EA01C3F7E9D00CD7F5A /* LTInfiniteScrollView-Swift.app */,
);
name = Products;
sourceTree = "<group>";
};
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 = "<group>";
};
FAA51EB51C3F7EAA00CD7F5A /* Sources */ = {
isa = PBXGroup;
children = (
FAA51EB61C3F7EE400CD7F5A /* LTInfiniteScrollView.swift */,
);
path = Sources;
sourceTree = "<group>";
};
/* 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 = "<group>";
};
/* 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
================================================
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:LTInfiniteScrollView-Swift.xcodeproj">
</FileRef>
</Workspace>
================================================
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
================================================

## Demo
##### 1. You can apply animation to each view during the scroll:

##### 2. The iOS 9 task switcher animation can be implemented in ten minutes with the support of this lib:

##### 3. The fancy menu can also be implemented easily:

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.
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
Condensed preview — 14 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (40K chars).
[
{
"path": ".gitignore",
"chars": 87,
"preview": ".DS_Store\n*.swp\n*~.nib\nPods\nbuild/\nxcuserdata/\n*.pbxuser\n*.perspective\n*.perspectivev3\n"
},
{
"path": ".swift-version",
"chars": 4,
"preview": "3.0\n"
},
{
"path": "LICENSE",
"chars": 1063,
"preview": "Copyright © 2015 ltebean\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software "
},
{
"path": "LTInfiniteScrollView-Swift/AppDelegate.swift",
"chars": 2174,
"preview": "//\n// AppDelegate.swift\n// LTInfiniteScrollView-Swift\n//\n// Created by ltebean on 16/1/8.\n// Copyright © 2016年 io. A"
},
{
"path": "LTInfiniteScrollView-Swift/Assets.xcassets/AppIcon.appiconset/Contents.json",
"chars": 585,
"preview": "{\n \"images\" : [\n {\n \"idiom\" : \"iphone\",\n \"size\" : \"29x29\",\n \"scale\" : \"2x\"\n },\n {\n \"idiom\""
},
{
"path": "LTInfiniteScrollView-Swift/Base.lproj/Main.storyboard",
"chars": 3084,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<document type=\"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard"
},
{
"path": "LTInfiniteScrollView-Swift/Info.plist",
"chars": 1198,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
},
{
"path": "LTInfiniteScrollView-Swift/Lauch.storyboard",
"chars": 448,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<document type=\"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard"
},
{
"path": "LTInfiniteScrollView-Swift/Sources/LTInfiniteScrollView.swift",
"chars": 9725,
"preview": "//\n// LTInfiniteScrollView.swift\n// LTInfiniteScrollView-Swift\n//\n// Created by ltebean on 16/1/8.\n// Copyright © 20"
},
{
"path": "LTInfiniteScrollView-Swift/ViewController.swift",
"chars": 2787,
"preview": "//\n// ViewController.swift\n// LTInfiniteScrollView-Swift\n//\n// Created by ltebean on 16/1/8.\n// Copyright © 2016年 io"
},
{
"path": "LTInfiniteScrollView-Swift.xcodeproj/project.pbxproj",
"chars": 11797,
"preview": "// !$*UTF8*$!\n{\n\tarchiveVersion = 1;\n\tclasses = {\n\t};\n\tobjectVersion = 46;\n\tobjects = {\n\n/* Begin PBXBuildFile section *"
},
{
"path": "LTInfiniteScrollView-Swift.xcodeproj/project.xcworkspace/contents.xcworkspacedata",
"chars": 171,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Workspace\n version = \"1.0\">\n <FileRef\n location = \"self:LTInfiniteScrol"
},
{
"path": "LTInfiniteScrollViewSwift.podspec",
"chars": 585,
"preview": "\nPod::Spec.new do |s|\n s.name = \"LTInfiniteScrollViewSwift\"\n s.version = \"0.5.0\"\n s.summary = \"An i"
},
{
"path": "README.md",
"chars": 2772,
"preview": "\n\n## Demo\n#####"
}
]
About this extraction
This page contains the full source code of the ltebean/LTInfiniteScrollView-Swift GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 14 files (35.6 KB), approximately 10.4k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.