diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..38e2e5d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,37 @@
+# Created by https://www.gitignore.io
+
+### Swift ###
+# Xcode
+#
+build/
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+xcuserdata
+*.xccheckout
+*.moved-aside
+DerivedData
+*.hmap
+*.ipa
+*.xcuserstate
+
+# CocoaPods
+#
+# We recommend against adding the Pods directory to your .gitignore. However
+# you should judge for yourself, the pros and cons are mentioned at:
+# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
+#
+
+Pods/
+
+# Carthage
+#
+# Add this line if you want to avoid checking in source code from Carthage dependencies.
+# Carthage/Checkouts
+
+Carthage/Build
diff --git a/Demos/.DS_Store b/Demos/.DS_Store
deleted file mode 100644
index 5008ddf..0000000
Binary files a/Demos/.DS_Store and /dev/null differ
diff --git a/Demos/TinderLike/.DS_Store b/Demos/TinderLike/.DS_Store
deleted file mode 100644
index 9ee1c77..0000000
Binary files a/Demos/TinderLike/.DS_Store and /dev/null differ
diff --git a/Demos/TinderLike/TinderLike.xcodeproj/project.xcworkspace/xcuserdata/stefan.xcuserdatad/UserInterfaceState.xcuserstate b/Demos/TinderLike/TinderLike.xcodeproj/project.xcworkspace/xcuserdata/stefan.xcuserdatad/UserInterfaceState.xcuserstate
deleted file mode 100644
index b1a9203..0000000
Binary files a/Demos/TinderLike/TinderLike.xcodeproj/project.xcworkspace/xcuserdata/stefan.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ
diff --git a/Demos/TinderLike/TinderLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Demos/TinderLike/TinderLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
deleted file mode 100644
index fe2b454..0000000
--- a/Demos/TinderLike/TinderLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
diff --git a/Demos/TinderLike/TinderLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcschemes/TinderLike.xcscheme b/Demos/TinderLike/TinderLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcschemes/TinderLike.xcscheme
deleted file mode 100644
index 5db44c2..0000000
--- a/Demos/TinderLike/TinderLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcschemes/TinderLike.xcscheme
+++ /dev/null
@@ -1,110 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Demos/TinderLike/TinderLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcschemes/xcschememanagement.plist b/Demos/TinderLike/TinderLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcschemes/xcschememanagement.plist
deleted file mode 100644
index d792c89..0000000
--- a/Demos/TinderLike/TinderLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcschemes/xcschememanagement.plist
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
- SchemeUserState
-
- TinderLike.xcscheme
-
- orderHint
- 0
-
-
- SuppressBuildableAutocreation
-
- F85CA9A41A61963B0013CF3F
-
- primary
-
-
- F85CA9B91A61963B0013CF3F
-
- primary
-
-
-
-
-
diff --git a/Demos/TwitterLike/.DS_Store b/Demos/TwitterLike/.DS_Store
deleted file mode 100644
index 1f3033c..0000000
Binary files a/Demos/TwitterLike/.DS_Store and /dev/null differ
diff --git a/Demos/TwitterLike/TwitterLike.xcodeproj/project.pbxproj b/Demos/TwitterLike/TwitterLike.xcodeproj/project.pbxproj
index 9305426..a5957bf 100644
--- a/Demos/TwitterLike/TwitterLike.xcodeproj/project.pbxproj
+++ b/Demos/TwitterLike/TwitterLike.xcodeproj/project.pbxproj
@@ -7,6 +7,9 @@
objects = {
/* Begin PBXBuildFile section */
+ F2AC2A751A834785006F8ADB /* PagingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2AC2A741A834785006F8ADB /* PagingViewController.swift */; };
+ F2E173031A8312F800784350 /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F2E173021A8312F800784350 /* Storyboard.storyboard */; };
+ F2E173051A83148200784350 /* DemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2E173041A83148200784350 /* DemoViewController.swift */; };
F85CA9771A618E180013CF3F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F85CA9761A618E180013CF3F /* AppDelegate.swift */; };
F85CA97E1A618E180013CF3F /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F85CA97D1A618E180013CF3F /* Images.xcassets */; };
F85CA98D1A618E180013CF3F /* TwitterLikeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F85CA98C1A618E180013CF3F /* TwitterLikeTests.swift */; };
@@ -25,6 +28,9 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
+ F2AC2A741A834785006F8ADB /* PagingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagingViewController.swift; sourceTree = ""; };
+ F2E173021A8312F800784350 /* Storyboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Storyboard.storyboard; sourceTree = ""; };
+ F2E173041A83148200784350 /* DemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DemoViewController.swift; sourceTree = ""; };
F85CA9711A618E180013CF3F /* TwitterLike.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TwitterLike.app; sourceTree = BUILT_PRODUCTS_DIR; };
F85CA9751A618E180013CF3F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
F85CA9761A618E180013CF3F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
@@ -80,6 +86,9 @@
F85CA9761A618E180013CF3F /* AppDelegate.swift */,
F85CA97D1A618E180013CF3F /* Images.xcassets */,
F85CA9741A618E180013CF3F /* Supporting Files */,
+ F2E173021A8312F800784350 /* Storyboard.storyboard */,
+ F2E173041A83148200784350 /* DemoViewController.swift */,
+ F2AC2A741A834785006F8ADB /* PagingViewController.swift */,
);
path = TwitterLike;
sourceTree = "";
@@ -201,6 +210,7 @@
files = (
F85CA97E1A618E180013CF3F /* Images.xcassets in Resources */,
F85CA9981A618E790013CF3F /* Default-568h@2x.png in Resources */,
+ F2E173031A8312F800784350 /* Storyboard.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -220,6 +230,8 @@
files = (
F85CA9771A618E180013CF3F /* AppDelegate.swift in Sources */,
F85CA9D11A6198F10013CF3F /* SLPagingViewSwift.swift in Sources */,
+ F2AC2A751A834785006F8ADB /* PagingViewController.swift in Sources */,
+ F2E173051A83148200784350 /* DemoViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -324,6 +336,7 @@
buildSettings = {
GCC_PREFIX_HEADER = "$SRCROOT/$PROJECT_NAME/TwitterLike-Prefix.pch";
INFOPLIST_FILE = TwitterLike/Info.plist;
+ IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
};
@@ -334,6 +347,7 @@
buildSettings = {
GCC_PREFIX_HEADER = "$SRCROOT/$PROJECT_NAME/TwitterLike-Prefix.pch";
INFOPLIST_FILE = TwitterLike/Info.plist;
+ IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
};
diff --git a/Demos/TwitterLike/TwitterLike.xcodeproj/project.xcworkspace/xcuserdata/stefan.xcuserdatad/UserInterfaceState.xcuserstate b/Demos/TwitterLike/TwitterLike.xcodeproj/project.xcworkspace/xcuserdata/stefan.xcuserdatad/UserInterfaceState.xcuserstate
deleted file mode 100644
index c16ec01..0000000
Binary files a/Demos/TwitterLike/TwitterLike.xcodeproj/project.xcworkspace/xcuserdata/stefan.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ
diff --git a/Demos/TwitterLike/TwitterLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Demos/TwitterLike/TwitterLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
deleted file mode 100644
index fe2b454..0000000
--- a/Demos/TwitterLike/TwitterLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
diff --git a/Demos/TwitterLike/TwitterLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcschemes/TwitterLike.xcscheme b/Demos/TwitterLike/TwitterLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcschemes/TwitterLike.xcscheme
deleted file mode 100644
index dc4eb09..0000000
--- a/Demos/TwitterLike/TwitterLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcschemes/TwitterLike.xcscheme
+++ /dev/null
@@ -1,110 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Demos/TwitterLike/TwitterLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcschemes/xcschememanagement.plist b/Demos/TwitterLike/TwitterLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcschemes/xcschememanagement.plist
deleted file mode 100644
index 6bcab09..0000000
--- a/Demos/TwitterLike/TwitterLike.xcodeproj/xcuserdata/stefan.xcuserdatad/xcschemes/xcschememanagement.plist
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
- SchemeUserState
-
- TwitterLike.xcscheme
-
- orderHint
- 0
-
-
- SuppressBuildableAutocreation
-
- F85CA9701A618E180013CF3F
-
- primary
-
-
- F85CA9851A618E180013CF3F
-
- primary
-
-
-
-
-
diff --git a/Demos/TwitterLike/TwitterLike/AppDelegate.swift b/Demos/TwitterLike/TwitterLike/AppDelegate.swift
index f38c29b..dd88075 100644
--- a/Demos/TwitterLike/TwitterLike/AppDelegate.swift
+++ b/Demos/TwitterLike/TwitterLike/AppDelegate.swift
@@ -9,131 +9,35 @@
import UIKit
@UIApplicationMain
-class AppDelegate: UIResponder, UIApplicationDelegate, UITableViewDelegate, UITableViewDataSource {
+class AppDelegate: UIResponder, UIApplicationDelegate {
- var window: UIWindow?
- var nav: UINavigationController?
- var controller: SLPagingViewSwift?
- var dataSource: NSMutableArray?
+ var window: UIWindow?
- func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
- self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
-
- self.dataSource = NSMutableArray(array: ["Hello world!", "Shaqtin' a fool!", "YEAHHH!",
- "Hello world!", "Shaqtin' a fool!", "YEAHHH!",
- "Hello world!", "Shaqtin' a fool!", "YEAHHH!",
- "Hello world!", "Shaqtin' a fool!", "YEAHHH!",
- "Hello world!", "Shaqtin' a fool!", "YEAHHH!"])
-
- var navTitleLabel1 = UILabel()
- navTitleLabel1.text = "Home"
- navTitleLabel1.font = UIFont(name: "Helvetica", size: 20)
- navTitleLabel1.textColor = UIColor.whiteColor()
- var navTitleLabel2 = UILabel()
- navTitleLabel2.text = "Discover"
- navTitleLabel2.font = UIFont(name: "Helvetica", size: 20)
- navTitleLabel2.textColor = UIColor.whiteColor()
- var navTitleLabel3 = UILabel()
- navTitleLabel3.text = "Activity"
- navTitleLabel3.font = UIFont(name: "Helvetica", size: 20)
- navTitleLabel3.textColor = UIColor.whiteColor()
-
- controller = SLPagingViewSwift(items: [navTitleLabel1, navTitleLabel2, navTitleLabel3], views: [self.tableView(), self.tableView(), self.tableView()], showPageControl: true, navBarBackground: UIColor(red: 0.33, green: 0.68, blue: 0.91, alpha: 1.0))
-
- controller?.currentPageControlColor = UIColor.whiteColor()
- controller?.tintPageControlColor = UIColor(white: 0.799, alpha: 1.0)
- controller?.pagingViewMovingRedefine = ({ scrollView, subviews in
- var i = 0
- var xOffset = scrollView.contentOffset.x
- for v in subviews {
- var lbl = v as UILabel
- var alpha = CGFloat(0)
-
- if(lbl.frame.origin.x > 45 && lbl.frame.origin.x < 145) {
- alpha = 1.0 - (xOffset - (CGFloat(i)*320.0)) / 320.0
- }
- else if (lbl.frame.origin.x > 145 && lbl.frame.origin.x < 245) {
- alpha = (xOffset - (CGFloat(i)*320.0)) / 320.0 + 1.0
- }
- else if(lbl.frame.origin.x == 145){
- alpha = 1.0
- }
- lbl.alpha = CGFloat(alpha)
- i++
- }
- })
-
- controller?.didChangedPage = ({ currentIndex in
- println(currentIndex)
- })
-
-
- self.nav = UINavigationController(rootViewController: self.controller!)
- self.window?.rootViewController = self.nav
- self.window?.backgroundColor = UIColor.whiteColor()
- self.window?.makeKeyAndVisible()
-
- return true
- }
+ func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
+ 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 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 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 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 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:.
- }
-
- func tableView() -> UITableView {
- var frame = CGRectMake(0, 0, 320, 568)
- frame.size.height -= 44
- var tableView = UITableView(frame: frame, style: .Plain)
- tableView.delegate = self
- tableView.dataSource = self
- tableView.scrollsToTop = false
- return tableView
- }
-
- // MARK: - UITableView DataSource
-
- func numberOfSectionsInTableView(tableView: UITableView) -> Int {
- return 1
- }
-
- func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return self.dataSource!.count
- }
-
- func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
- return 120.0
- }
-
- func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
- var cellIdentifier = "cellIdentifier"
- var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell
- if cell == nil {
- cell = UITableViewCell(style: .Default, reuseIdentifier: cellIdentifier)
- cell?.textLabel?.numberOfLines = 0
- }
- cell!.imageView?.image = UIImage(named: NSString(format: "avatar_%d.jpg", indexPath.row % 3))
- cell!.textLabel!.text = self.dataSource?.objectAtIndex(indexPath.row) as String
-
- return cell!
- }
+ func applicationWillTerminate(application: UIApplication) {
+ // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+ }
}
diff --git a/Demos/TwitterLike/TwitterLike/DemoViewController.swift b/Demos/TwitterLike/TwitterLike/DemoViewController.swift
new file mode 100644
index 0000000..ea73588
--- /dev/null
+++ b/Demos/TwitterLike/TwitterLike/DemoViewController.swift
@@ -0,0 +1,118 @@
+//
+// DemoTableViewController.swift
+// TwitterLike
+//
+// Created by Retso Huang on 2/5/15.
+// Copyright (c) 2015 Stefan Lage. All rights reserved.
+//
+
+import UIKit
+
+class DemoViewController: UIViewController {
+
+ // MARK: - Constants
+ private let dataSource = ["Hello world!", "Shaqtin' a fool!", "YEAHHH!",
+ "Hello world!", "Shaqtin' a fool!", "YEAHHH!",
+ "Hello world!", "Shaqtin' a fool!", "YEAHHH!",
+ "Hello world!", "Shaqtin' a fool!", "YEAHHH!",
+ "Hello world!", "Shaqtin' a fool!", "YEAHHH!"]
+
+ private var demoTableView: UITableView {
+ let demoTableView = UITableView(frame: self.view.frame, style: .Plain)
+ demoTableView.dataSource = self
+ demoTableView.scrollsToTop = false
+ return demoTableView
+ }
+
+ // MARK: - Life Cycle
+ override func viewDidLoad() {
+ super.viewDidLoad()
+ }
+
+ override func didReceiveMemoryWarning() {
+ super.didReceiveMemoryWarning()
+ }
+
+ // MARK: - User Control Events
+ @IBAction func pushProgrammatically() {
+ let font = UIFont(name: "Helvetica", size: 20)
+
+ var navTitleLabel1 = UILabel()
+ navTitleLabel1.text = "Home"
+ navTitleLabel1.font = font
+ navTitleLabel1.textColor = UIColor.whiteColor()
+ var navTitleLabel2 = UILabel()
+ navTitleLabel2.text = "Discover"
+ navTitleLabel2.font = font
+ navTitleLabel2.textColor = UIColor.whiteColor()
+ var navTitleLabel3 = UILabel()
+ navTitleLabel3.text = "Activity"
+ navTitleLabel3.font = font
+ navTitleLabel3.textColor = UIColor.whiteColor()
+
+ let pagingController = SLPagingViewSwift(items: [navTitleLabel1, navTitleLabel2, navTitleLabel3], viewsOrControllers: [self.demoTableView, self.demoTableView, self.demoTableView], showPageControl: true, navBarBackground: UIColor(red: 0.33, green: 0.68, blue: 0.91, alpha: 1.0))
+
+ pagingController.currentPageControlColor = UIColor.whiteColor()
+ pagingController.tintPageControlColor = UIColor(white: 0.799, alpha: 1.0)
+ pagingController.pagingViewMovingRedefine = {
+ (scrollView: UIScrollView, subviews: [UIView]) -> Void in
+ var i = 0
+ var xOffset = scrollView.contentOffset.x
+ for view in subviews {
+ if let titleLabel = view as? UILabel {
+ var alpha = CGFloat(0)
+
+ if(titleLabel.frame.origin.x > 45 && titleLabel.frame.origin.x < 145) {
+ alpha = 1.0 - (xOffset - (CGFloat(i)*320.0)) / 320.0
+ }
+ else if (titleLabel.frame.origin.x > 145 && titleLabel.frame.origin.x < 245) {
+ alpha = (xOffset - (CGFloat(i)*320.0)) / 320.0 + 1.0
+ }
+ else if(titleLabel.frame.origin.x == 145){
+ alpha = 1.0
+ }
+ titleLabel.alpha = CGFloat(alpha)
+ i++
+ }
+ }
+ }
+
+ pagingController.didChangedPage = ({ currentIndex in
+ println(currentIndex)
+ })
+
+ self.navigationController?.pushViewController(pagingController, animated: true)
+
+ }
+
+}
+
+// MARK: - UITableViewDataSource
+extension DemoViewController: UITableViewDataSource {
+ func numberOfSectionsInTableView(tableView: UITableView) -> Int {
+ return 1
+ }
+
+ func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+ return dataSource.count
+ }
+
+ func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
+ return 120.0
+ }
+
+ func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
+ var cellIdentifier = "cellIdentifier"
+
+ var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell
+
+ if cell == nil {
+ cell = UITableViewCell(style: .Default, reuseIdentifier: cellIdentifier)
+ cell?.textLabel?.numberOfLines = 0
+ }
+ cell!.imageView?.image = UIImage(named: "avatar_\(indexPath.row % 3)")
+ cell!.textLabel!.text = self.dataSource[indexPath.row]
+
+ return cell!
+ }
+}
diff --git a/Demos/TwitterLike/TwitterLike/Info.plist b/Demos/TwitterLike/TwitterLike/Info.plist
index 8b0b716..74145da 100644
--- a/Demos/TwitterLike/TwitterLike/Info.plist
+++ b/Demos/TwitterLike/TwitterLike/Info.plist
@@ -22,6 +22,8 @@
1
LSRequiresIPhoneOS
+ UIMainStoryboardFile
+ Storyboard
UIRequiredDeviceCapabilities
armv7
diff --git a/Demos/TwitterLike/TwitterLike/PagingViewController.swift b/Demos/TwitterLike/TwitterLike/PagingViewController.swift
new file mode 100644
index 0000000..d083593
--- /dev/null
+++ b/Demos/TwitterLike/TwitterLike/PagingViewController.swift
@@ -0,0 +1,48 @@
+//
+// PagingViewController.swift
+// TwitterLike
+//
+// Created by Retso Huang on 2/5/15.
+// Copyright (c) 2015 Stefan Lage. All rights reserved.
+//
+
+import UIKit
+
+class PagingViewController: SLPagingViewSwift {
+
+ override func viewDidLoad() {
+ super.viewDidLoad()
+ let brownViewController = self.storyboard?.instantiateViewControllerWithIdentifier("BrownViewController") as UIViewController
+ let purpleViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PurpleViewController") as UIViewController
+ self.addViewControllers([brownViewController, purpleViewController])
+ self.needToShowPageControl = true
+ self.pagingViewMovingRedefine = {
+ (scrollView: UIScrollView, subviews: [UIView]) -> Void in
+ var i = 0
+ var xOffset = scrollView.contentOffset.x
+ for view in subviews {
+ if let titleLabel = view as? UILabel {
+ var alpha = CGFloat(0)
+
+ if(titleLabel.frame.origin.x > 45 && titleLabel.frame.origin.x < 145) {
+ alpha = 1.0 - (xOffset - (CGFloat(i)*320.0)) / 320.0
+ }
+ else if (titleLabel.frame.origin.x > 145 && titleLabel.frame.origin.x < 245) {
+ alpha = (xOffset - (CGFloat(i)*320.0)) / 320.0 + 1.0
+ }
+ else if(titleLabel.frame.origin.x == 145){
+ alpha = 1.0
+ }
+ titleLabel.alpha = CGFloat(alpha)
+ i++
+ }
+ }
+ }
+
+ }
+
+ override func didReceiveMemoryWarning() {
+ super.didReceiveMemoryWarning()
+ }
+
+}
diff --git a/Demos/TwitterLike/TwitterLike/Storyboard.storyboard b/Demos/TwitterLike/TwitterLike/Storyboard.storyboard
new file mode 100644
index 0000000..5b5b752
--- /dev/null
+++ b/Demos/TwitterLike/TwitterLike/Storyboard.storyboard
@@ -0,0 +1,128 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SLPagingViewSwift/SLPagingViewSwift.swift b/SLPagingViewSwift/SLPagingViewSwift.swift
index ff35af4..7b96490 100644
--- a/SLPagingViewSwift/SLPagingViewSwift.swift
+++ b/SLPagingViewSwift/SLPagingViewSwift.swift
@@ -18,331 +18,347 @@ enum SLNavigationSideItemsStyle: Int {
}
typealias SLPagingViewMoving = ((subviews: NSArray)-> ())
-typealias SLPagingViewMovingRedefine = ((scrollView: UIScrollView, subviews: NSArray)-> ())
+typealias SLPagingViewMovingRedefine = (scrollView: UIScrollView, subviews: [UIView]) -> Void
typealias SLPagingViewDidChanged = ((currentPage: NSInteger)-> ())
-class SLPagingViewSwift: UIViewController, UIScrollViewDelegate {
+public class SLPagingViewSwift: UIViewController, UIScrollViewDelegate {
- // MARK: - Public properties
- var viewControllers: NSDictionary = NSDictionary()
- var currentPageControlColor: UIColor?
- var tintPageControlColor: UIColor?
- var pagingViewMoving: SLPagingViewMoving?
- var pagingViewMovingRedefine: SLPagingViewMovingRedefine?
- var didChangedPage: SLPagingViewDidChanged?
- var navigationSideItemsStyle: SLNavigationSideItemsStyle = .SLNavigationSideItemsStyleDefault
-
- // MARK: - Private properties
- private var SCREENSIZE: CGSize {
- return UIScreen.mainScreen().bounds.size
- }
- private var scrollView: UIScrollView = UIScrollView()
- private var pageControl: UIPageControl = UIPageControl()
- private var navigationBarView: UIView = UIView()
- private var navItems: NSMutableArray = NSMutableArray()
- private var needToShowPageControl: Bool = false
- private var isUserInteraction: Bool = false
- private var indexSelected: NSInteger = 0
-
- // MARK: - Constructors
- required init(coder decoder: NSCoder) {
- super.init(coder: decoder)
+ // MARK: - Public properties
+ weak var embedNavigationController: UINavigationController?
+ var viewsOrContrllers = [Int: UIResponder]()
+ var currentPageControlColor: UIColor?
+ var tintPageControlColor: UIColor? {
+ didSet {
+ setupPagingProcess()
}
-
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
- super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
- // Here you can init your properties
+ }
+ var pagingViewMoving: SLPagingViewMoving?
+ var pagingViewMovingRedefine: SLPagingViewMovingRedefine? {
+ didSet {
+ if let pagingViewMovingAnimation = self.pagingViewMovingRedefine {
+ pagingViewMovingAnimation(scrollView: scrollView, subviews: self.navigationItems)
+ }
}
-
- // MARK: - Constructors with items & views
- convenience init(items: NSArray, views: NSArray) {
- self.init(items: items, views: views, showPageControl:false, navBarBackground:UIColor.whiteColor())
- }
-
- convenience init(items: NSArray, views: NSArray, showPageControl: Bool){
- self.init(items: items, views: views, showPageControl:showPageControl, navBarBackground:UIColor.whiteColor())
- }
-
- /*
- * SLPagingViewController's constructor
- *
- * @param items should contain all subviews of the navigation bar
- * @param navBarBackground navigation bar's background color
- * @param views all subviews corresponding to each page
- * @param showPageControl inform if we need to display the page control in the navigation bar
- *
- * @return Instance of SLPagingViewController
- */
- init(items: NSArray, views: NSArray, showPageControl: Bool, navBarBackground: UIColor){
- super.init()
- needToShowPageControl = showPageControl
- navigationBarView.backgroundColor = navBarBackground
- isUserInteraction = true
- var i: Int = 0
- for item in items{
- if item.isKindOfClass(UIView.classForCoder()){
- var v = item as UIView
- var vSize: CGSize = v.isKindOfClass(UILabel.classForCoder()) ? self.getLabelSize(v as UILabel) : v.frame.size
- var originX = (self.SCREENSIZE.width/2.0 - vSize.width/2.0) + CGFloat(i * 100)
- v.frame = CGRectMake(originX, 8, vSize.width, vSize.height)
- v.tag = i
- var tap = UITapGestureRecognizer(target: self, action: "tapOnHeader:")
- v.addGestureRecognizer(tap)
- v.userInteractionEnabled = true
- self.navigationBarView.addSubview(v)
- self.navItems.addObject(v)
- i++
- }
- }
-
- if (views.count > 0){
- var controllerKeys = NSMutableArray()
- i = 0
- for controller in views{
- if controller.isKindOfClass(UIView.classForCoder()){
- var ctr = controller as UIView
- ctr.tag = i
- controllerKeys.addObject(NSNumber(integer: i))
- }
- else if controller.isKindOfClass(UIViewController.classForCoder()){
- var ctr = controller as UIViewController
- ctr.view.tag = i
- controllerKeys.addObject(NSNumber(integer: i))
- }
- i++
- }
-
- if controllerKeys.count == views.count {
- self.viewControllers = NSDictionary(objects: views, forKeys: controllerKeys)
- }
- else{
- var exc = NSException(name: "View Controllers error", reason: "Some objects in viewControllers are not kind of UIViewController!", userInfo: nil)
- exc.raise()
- }
- }
- }
-
- // MARK: - Constructors with controllers
- convenience init(controllers: NSArray){
- self.init(controllers: controllers, showPageControl: true, navBarBackground: UIColor.whiteColor())
+ }
+ var didChangedPage: SLPagingViewDidChanged?
+ var navigationSideItemsStyle: SLNavigationSideItemsStyle = .SLNavigationSideItemsStyleDefault
+ public var needToShowPageControl: Bool = false {
+ didSet {
+ setupPagingProcess()
}
-
- convenience init(controllers: NSArray, showPageControl: Bool){
- self.init(controllers: controllers, showPageControl: true, navBarBackground: UIColor.whiteColor())
- }
-
- /*
- * SLPagingViewController's constructor
- *
- * Use controller's title as a navigation item
- *
- * @param controllers view controllers containing sall subviews corresponding to each page
- * @param navBarBackground navigation bar's background color
- * @param showPageControl inform if we need to display the page control in the navigation bar
- *
- * @return Instance of SLPagingViewController
- */
- convenience init(controllers: NSArray, showPageControl: Bool, navBarBackground: UIColor){
- var views = NSMutableArray()
- var items = NSMutableArray()
- for ctr in controllers {
- if ctr.isKindOfClass(UIViewController.classForCoder()) {
- views.addObject(ctr)
- var item = UILabel()
- item.text = ctr.title
- items.addObject(item)
- }
- }
- self.init(items: items, views: views, showPageControl:showPageControl, navBarBackground:navBarBackground)
+ }
+
+ // MARK: - Private properties
+ private var scrollView: UIScrollView = UIScrollView()
+ private var pageControl: UIPageControl = UIPageControl()
+ private var navigationBarView: UIView = UIView()
+ private var navigationItems = [UIView]()
+ private var isUserInteraction: Bool = false
+ private var indexSelected: NSInteger = 0
+
+ // MARK: - Constructors
+ required public init(coder decoder: NSCoder) {
+ super.init(coder: decoder)
+ }
+
+ override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
+ super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
+ // Here you can init your properties
+ }
+
+ // MARK: - Constructors with controllers
+
+ /*
+ * SLPagingViewController's constructor
+ *
+ * Use controller's title as a navigation item
+ *
+ * @param controllers view controllers containing sall subviews corresponding to each page
+ * @param navBarBackground navigation bar's background color
+ * @param showPageControl inform if we need to display the page control in the navigation bar
+ *
+ * @return Instance of SLPagingViewController
+ */
+ convenience init(controllers: [UIViewController], showPageControl: Bool = true, navBarBackground: UIColor = UIColor.whiteColor()) {
+ self.init(items: SLPagingViewSwift.navigationTitleLabels(controllers), viewsOrControllers: controllers, showPageControl:showPageControl, navBarBackground:navBarBackground)
+ }
+
+ // MARK: - Constructors with items & controllers
+
+ /*
+ * SLPagingViewController's constructor
+ *
+ * @param items should contain all subviews of the navigation bar
+ * @param navBarBackground navigation bar's background color
+ * @param controllers view controllers containing sall subviews corresponding to each page
+ * @param showPageControl inform if we need to display the page control in the navigation bar
+ *
+ * @return Instance of SLPagingViewController
+ */
+ convenience init(items: [UIView], controllers: [UIViewController], showPageControl: Bool = true, navBarBackground: UIColor = UIColor.whiteColor()) {
+ self.init(items: items, viewsOrControllers: controllers, showPageControl:showPageControl, navBarBackground:navBarBackground)
+ }
+
+ // MARK: - Constructors with items & views
+
+ /*
+ * SLPagingViewController's constructor
+ *
+ * @param items should contain all subviews of the navigation bar
+ * @param navBarBackground navigation bar's background color
+ * @param viewsOrControllers all view or view controller corresponding to each page
+ * @param showPageControl inform if we need to display the page control in the navigation bar
+ *
+ * @return Instance of SLPagingViewController
+ */
+ init(items: [UIView], viewsOrControllers: [UIResponder], showPageControl: Bool = false, navBarBackground: UIColor = UIColor.whiteColor()) {
+ super.init()
+ needToShowPageControl = showPageControl
+ navigationBarView.backgroundColor = navBarBackground
+ isUserInteraction = true
+ self.setup(items, viewsOrControllers: viewsOrControllers)
+ }
+
+ // MARK: - Public methods
+
+ /**
+ Add UIViewController(s) in to scrool View and automatically add navigation title as same as call init(controllers:showPageControl:navBarBackground:).
+
+ :param: viewControllers view controllers containing sall subviews corresponding to each page
+ */
+ public func addViewControllers(viewControllers: [UIViewController]) {
+ self.setup(SLPagingViewSwift.navigationTitleLabels(viewControllers), viewsOrControllers: viewControllers)
+ self.setupPagingProcess()
+ self.setCurrentIndex(self.indexSelected, animated: false)
+ }
+
+ /*
+ * Update the state of the UserInteraction on the navigation bar
+ *
+ * @param activate state you want to set to UserInteraction
+ */
+ func updateUserInteractionOnNavigation(active: Bool){
+ self.isUserInteraction = active
+ }
+
+ /*
+ * Set the current index page and scroll to its position
+ *
+ * @param index of the wanted page
+ * @param animated animate the moving
+ */
+ func setCurrentIndex(index: NSInteger, animated: Bool){
+ // Be sure we got an existing index
+ if(index < 0 || index > self.navigationBarView.subviews.count - 1){
+ var exc = NSException(name: "Index out of range", reason: "The index is out of range of subviews's countsd!", userInfo: nil)
+ exc.raise()
}
-
- // MARK: - Constructors with items & controllers
- convenience init(items: NSArray, controllers: NSArray){
- self.init(items: items, controllers: controllers, showPageControl: true, navBarBackground: UIColor.whiteColor())
+ self.indexSelected = index
+ // Get the right position and update it
+ var xOffset = CGFloat(index) * self.view.frame.width
+ self.scrollView.setContentOffset(CGPointMake(xOffset, self.scrollView.contentOffset.y), animated: animated)
+ }
+
+ // MARK: - Life cycle
+ override public func viewDidLoad() {
+ super.viewDidLoad()
+ if self.viewsOrContrllers.count > 0 {
+ self.setupPagingProcess()
+ self.setCurrentIndex(self.indexSelected, animated: false)
}
- convenience init(items: NSArray, controllers: NSArray, showPageControl: Bool){
- self.init(items: items, controllers: controllers, showPageControl: showPageControl, navBarBackground: UIColor.whiteColor())
+ }
+
+ public override func viewDidLayoutSubviews() {
+ super.viewDidLayoutSubviews()
+ }
+
+ public override func viewWillAppear(animated: Bool) {
+ super.viewWillAppear(animated)
+ self.childViewControllers
+ for viewOrViewController in self.viewsOrContrllers.values {
+ if let viewController = viewOrViewController as? UIViewController {
+ viewController.willMoveToParentViewController(self)
+ }
}
-
- /*
- * SLPagingViewController's constructor
- *
- * @param items should contain all subviews of the navigation bar
- * @param navBarBackground navigation bar's background color
- * @param controllers view controllers containing sall subviews corresponding to each page
- * @param showPageControl inform if we need to display the page control in the navigation bar
- *
- * @return Instance of SLPagingViewController
- */
- convenience init(items: NSArray, controllers: NSArray, showPageControl: Bool, navBarBackground: UIColor){
- var views = NSMutableArray()
- for ctr in controllers {
- if ctr.isKindOfClass(UIViewController.classForCoder()) {
- views.addObject(ctr.valueForKey("view")!)
- }
- }
- self.init(items: items, views: views, showPageControl:showPageControl, navBarBackground:navBarBackground)
+ }
+
+ public override func viewDidAppear(animated: Bool) {
+ super.viewDidAppear(animated)
+ for viewOrViewController in self.viewsOrContrllers.values {
+ if let viewController = viewOrViewController as? UIViewController {
+ viewController.didMoveToParentViewController(self)
+ }
}
-
- // MARK: - Life cycle
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- self.setupPagingProcess()
- self.setCurrentIndex(self.indexSelected, animated: false)
+ if let navigationController = self.embedNavigationController {
+ navigationController.navigationBar.addSubview(self.navigationBarView)
+ } else if let navigationController = self.navigationController {
+ navigationController.navigationBar.addSubview(self.navigationBarView)
}
-
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
+ }
+
+ public override func viewWillDisappear(animated: Bool) {
+ super.viewWillDisappear(animated)
+ self.navigationBarView.removeFromSuperview()
+ }
+
+ override public func didReceiveMemoryWarning() {
+ super.didReceiveMemoryWarning()
+ }
+
+ // MARK: - Internal methods
+ private func setup(items: [UIView], viewsOrControllers: [UIResponder]) {
+ var i = 0
+ for item in items {
+ var vSize: CGSize = item.isKindOfClass(UILabel.classForCoder()) ? self.getLabelSize(item as UILabel) : item.frame.size
+ var originX = (self.view.frame.width/2.0 - vSize.width/2.0) + CGFloat(i * 100)
+ item.frame = CGRectMake(originX, 8, vSize.width, vSize.height)
+ item.tag = i
+ var tap = UITapGestureRecognizer(target: self, action: "tapOnHeader:")
+ item.addGestureRecognizer(tap)
+ item.userInteractionEnabled = true
+ self.navigationBarView.addSubview(item)
+ self.navigationItems.append(item)
+ i++
}
- override func viewWillLayoutSubviews() {
- super.viewWillLayoutSubviews()
- self.navigationBarView.frame = CGRectMake(0, 0, self.SCREENSIZE.width, 44)
+ var index = 0
+ for viewOrController in viewsOrControllers {
+ if let view = viewOrController as? UIView {
+ view.tag = index
+ viewsOrContrllers[index] = view
+ }
+ if let viewController = viewOrController as? UIViewController {
+ self.addChildViewController(viewController)
+ viewController.view.tag = index
+ viewsOrContrllers[index] = viewController
+ }
+ index++
}
-
- // MARK: - Public methods
-
- /*
- * Update the state of the UserInteraction on the navigation bar
- *
- * @param activate state you want to set to UserInteraction
- */
- func updateUserInteractionOnNavigation(active: Bool){
- self.isUserInteraction = active
+ }
+ private class func navigationTitleLabels(viewControllers: [UIViewController]) -> [UILabel] {
+ var titleLabels = [UILabel]()
+ for viewController in viewControllers {
+ var titleLabel = UILabel()
+ titleLabel.text = viewController.title
+ titleLabels.append(titleLabel)
}
-
- /*
- * Set the current index page and scroll to its position
- *
- * @param index of the wanted page
- * @param animated animate the moving
- */
- func setCurrentIndex(index: NSInteger, animated: Bool){
- // Be sure we got an existing index
- if(index < 0 || index > self.navigationBarView.subviews.count-1){
- var exc = NSException(name: "Index out of range", reason: "The index is out of range of subviews's countsd!", userInfo: nil)
- exc.raise()
- }
- self.indexSelected = index
- // Get the right position and update it
- var xOffset = CGFloat(index) * self.SCREENSIZE.width
- self.scrollView.setContentOffset(CGPointMake(xOffset, self.scrollView.contentOffset.y), animated: animated)
- }
-
- // MARK: - Internal methods
- private func setupPagingProcess() {
- var frame: CGRect = CGRectMake(0, 0, SCREENSIZE.width, self.view.frame.height)
+ return titleLabels
+ }
+ private func setupPagingProcess() {
+ self.scrollView = UIScrollView(frame: self.view.frame)
+ self.scrollView.backgroundColor = UIColor.clearColor()
+ self.scrollView.pagingEnabled = true
+ self.scrollView.showsHorizontalScrollIndicator = false
+ self.scrollView.showsVerticalScrollIndicator = false
+ self.scrollView.delegate = self
+ self.scrollView.bounces = false
+ self.view.addSubview(self.scrollView)
- self.scrollView = UIScrollView(frame: frame)
- self.scrollView.backgroundColor = UIColor.clearColor()
- self.scrollView.pagingEnabled = true
- self.scrollView.showsHorizontalScrollIndicator = false
- self.scrollView.showsVerticalScrollIndicator = false
- self.scrollView.delegate = self
- self.scrollView.bounces = false
- self.scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: -80, right: 0)
-
- self.view.addSubview(self.scrollView)
-
- // Adds all views
- self.addViews()
-
- if(self.needToShowPageControl){
- // Make the page control
- self.pageControl = UIPageControl(frame: CGRectMake(0, 35, 0, 0))
- self.pageControl.numberOfPages = self.navigationBarView.subviews.count
- self.pageControl.currentPage = 0
- if self.currentPageControlColor != nil {
- self.pageControl.currentPageIndicatorTintColor = self.currentPageControlColor
- }
- if self.tintPageControlColor != nil {
- self.pageControl.pageIndicatorTintColor = self.tintPageControlColor
- }
- self.navigationBarView.addSubview(self.pageControl)
- }
-
- self.navigationController?.navigationBar.addSubview(self.navigationBarView)
-
- }
-
- // Loads all views
- private func addViews() {
- if self.viewControllers.count > 0 {
- let width = SCREENSIZE.width * CGFloat(self.viewControllers.count)
- let height = self.view.frame.height
- self.scrollView.contentSize = CGSize(width: width, height: height)
- var i: Int = 0
- self.viewControllers.enumerateKeysAndObjectsUsingBlock({ key, obj, stop in
- var rect: CGRect = CGRectMake(self.SCREENSIZE.width * CGFloat(i), 0, self.SCREENSIZE.width, self.SCREENSIZE.height)
- var v = obj as UIView
- v.frame = rect
- self.scrollView.addSubview(v)
- i++
- })
- }
- }
-
- private func getLabelSize(lbl: UILabel) -> CGSize{
- var txt = lbl.text!
- return txt.sizeWithAttributes([NSFontAttributeName: lbl.font])
- }
+ // Adds all views
+ self.addViews()
+
+ self.pageControl.removeFromSuperview()
- private func sendNewIndex(scrollView: UIScrollView){
- var xOffset = Float(scrollView.contentOffset.x)
- var currentIndex = (Int(roundf(xOffset)) % (self.navigationBarView.subviews.count * Int(self.SCREENSIZE.width))) / Int(self.SCREENSIZE.width)
- if(self.pageControl.currentPage != currentIndex) {
- self.pageControl.currentPage = currentIndex
- if self.didChangedPage != nil {
- self.didChangedPage!(currentPage: currentIndex)
- }
- }
+ if(self.needToShowPageControl){
+ // Make the page control
+ self.pageControl = UIPageControl(frame: CGRectMake(0, 35, self.view.frame.size.width, 0))
+ self.pageControl.numberOfPages = self.navigationBarView.subviews.count
+ self.pageControl.currentPage = 0
+ if self.currentPageControlColor != nil {
+ self.pageControl.currentPageIndicatorTintColor = self.currentPageControlColor
+ }
+ if self.tintPageControlColor != nil {
+ self.pageControl.pageIndicatorTintColor = self.tintPageControlColor
+ }
+ self.navigationBarView.addSubview(self.pageControl)
}
- func getOriginX(vSize: CGSize, idx: CGFloat, distance: CGFloat, xOffset: CGFloat) -> CGFloat{
- var result = self.SCREENSIZE.width / 2.0 - vSize.width/2.0
- result += (idx * distance)
- result -= xOffset / (self.SCREENSIZE.width / distance)
- return result
+ }
+
+ // Loads all views
+ private func addViews() {
+ for (key, viewOrViewController) in viewsOrContrllers {
+ let width = self.view.frame.width * CGFloat(viewsOrContrllers.count)
+ let height = self.view.frame.height
+ self.scrollView.contentSize = CGSize(width: width, height: height)
+ let viewFrame = CGRect(x: self.view.frame.width * CGFloat(key), y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
+ if let view = viewOrViewController as? UIView {
+ view.frame = viewFrame
+ scrollView.addSubview(view)
+ }
+ if let viewController = viewOrViewController as? UIViewController {
+ viewController.view.frame = viewFrame
+ scrollView.addSubview(viewController.view)
+ }
}
-
- // Scroll to the view tapped
- func tapOnHeader(recognizer: UITapGestureRecognizer){
- if(self.isUserInteraction){
- var key = recognizer.view?.tag
- var view = self.viewControllers.objectForKey(NSNumber(integer: key!)) as UIView
- self.scrollView.scrollRectToVisible(view.frame, animated: true)
+ }
+
+ private func getLabelSize(lbl: UILabel) -> CGSize{
+ var txt = lbl.text!
+ return txt.sizeWithAttributes([NSFontAttributeName: lbl.font])
+ }
+
+ private func sendNewIndex(scrollView: UIScrollView){
+ var xOffset = Float(scrollView.contentOffset.x)
+ var currentIndex = (Int(roundf(xOffset)) % (self.navigationBarView.subviews.count * Int(self.view.frame.width))) / Int(self.view.frame.size.width)
+ if(self.pageControl.currentPage != currentIndex) {
+ self.pageControl.currentPage = currentIndex
+ if self.didChangedPage != nil {
+ self.didChangedPage!(currentPage: currentIndex)
+ }
+ }
+ }
+
+ func getOriginX(vSize: CGSize, idx: CGFloat, distance: CGFloat, xOffset: CGFloat) -> CGFloat{
+ var result = self.view.frame.size.width / 2.0 - vSize.width/2.0
+ result += (idx * distance)
+ result -= xOffset / (self.view.frame.size.width / distance)
+ return result
+ }
+
+ // Scroll to the view tapped
+ func tapOnHeader(recognizer: UITapGestureRecognizer){
+ if(self.isUserInteraction){
+ if let key = recognizer.view?.tag {
+ var viewToScroll: UIView!
+ if let view = viewsOrContrllers[key] as? UIView {
+ viewToScroll = view
+ } else if let viewController = viewsOrContrllers[key] as? UIViewController {
+ viewToScroll = viewController.view
+ }
+ self.scrollView.scrollRectToVisible(viewToScroll.frame, animated: true)
}
- }
+ }
+ }
- // MARK: - UIScrollViewDelegate
-
- func scrollViewDidScroll(scrollView: UIScrollView) {
- var xOffset = scrollView.contentOffset.x
- var i = 0
- for obj in self.navItems {
- var v:UIView = obj as UIView
- var distance = 100 + self.navigationSideItemsStyle.rawValue
- var vSize = v.frame.size
- var originX = self.getOriginX(vSize, idx: CGFloat(i), distance: CGFloat(distance), xOffset: CGFloat(xOffset))
- v.frame = CGRectMake(originX, 8, vSize.width, vSize.height)
- i++
- }
- if (self.pagingViewMovingRedefine != nil) {
- self.pagingViewMovingRedefine!(scrollView: scrollView, subviews: self.navItems)
- }
- if (self.pagingViewMoving != nil) {
- self.pagingViewMoving!(subviews: self.navItems)
- }
+}
+
+// MARK: - UIScrollViewDelegate
+extension SLPagingViewSwift: UIScrollViewDelegate {
+ public func scrollViewDidScroll(scrollView: UIScrollView) {
+ var xOffset = scrollView.contentOffset.x
+ var i = 0
+ for obj in self.navigationItems {
+ var v:UIView = obj as UIView
+ var distance = 100 + self.navigationSideItemsStyle.rawValue
+ var vSize = v.frame.size
+ var originX = self.getOriginX(vSize, idx: CGFloat(i), distance: CGFloat(distance), xOffset: CGFloat(xOffset))
+ v.frame = CGRectMake(originX, 8, vSize.width, vSize.height)
+ i++
}
-
- func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
- self.sendNewIndex(scrollView)
+ if let pagingViewMovingAnimation = self.pagingViewMovingRedefine {
+ pagingViewMovingAnimation(scrollView: scrollView, subviews: self.navigationItems)
}
-
- func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
- self.sendNewIndex(scrollView)
+ if let pagingViewMoving = self.pagingViewMoving {
+ pagingViewMoving(subviews: self.navigationItems)
}
-
+ }
+
+ public func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
+ self.sendNewIndex(scrollView)
+ }
+
+ public func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
+ self.sendNewIndex(scrollView)
+ }
}
\ No newline at end of file