Merge pull request #226 from xmartlabs/Swift3
Convert XLPagerTabStrip to Swift 3
This commit is contained in:
commit
794f085a63
|
|
@ -1,7 +1,7 @@
|
|||
language: objective-c
|
||||
osx_image: xcode7.3
|
||||
osx_image: xcode8
|
||||
env:
|
||||
- DESTINATION="OS=9.3,name=iPhone 6s" SCHEME="XLPagerTabStrip" SDK=iphonesimulator9.3
|
||||
- DESTINATION="OS=10.0,name=iPhone 6s" SCHEME="XLPagerTabStrip" SDK=iphonesimulator10.0
|
||||
before_install:
|
||||
- brew update
|
||||
#- brew outdated carthage || brew upgrade carthage
|
||||
|
|
@ -10,7 +10,7 @@ before_install:
|
|||
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
|
||||
|
||||
script:
|
||||
- xctool clean build -project XLPagerTabStrip.xcodeproj -scheme XLPagerTabStrip -sdk iphonesimulator9.3
|
||||
#- xctool test -project XLPagerTabStrip.xcodeproj -scheme XLPagerTabStrip -sdk iphonesimulator9.3
|
||||
- xcodebuild clean build -project XLPagerTabStrip.xcodeproj -scheme "$SCHEME" -sdk "$SDK"
|
||||
#- xcodebuild test -project XLPagerTabStrip.xcodeproj -scheme "$SCHEME" -sdk "$SDK"
|
||||
- xcodebuild -project XLPagerTabStrip.xcodeproj -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION"
|
||||
-configuration Debug ONLY_ACTIVE_ARCH=NO test | xcpretty -c
|
||||
|
|
|
|||
|
|
@ -1,6 +1,15 @@
|
|||
# Change Log
|
||||
All notable changes to XLPagerTabStrip will be documented in this file.
|
||||
|
||||
### [6.0.0](https://github.com/xmartlabs/XLPagerTabStrip/releases/tag/5.0.0)
|
||||
|
||||
* Swift 3 support
|
||||
* **Breaking change**: Swiftified names of functions (you can see more details about it [here](https://github.com/xmartlabs/XLPagerTabStrip/Migration.md))
|
||||
|
||||
### [5.1.0](https://github.com/xmartlabs/XLPagerTabStrip/releases/tag/5.0.0)
|
||||
|
||||
* Xcode 8 support. (Swift 2.3)
|
||||
|
||||
### [5.0.0](https://github.com/xmartlabs/XLPagerTabStrip/releases/tag/5.0.0)
|
||||
|
||||
* Xcode 7.3 support.
|
||||
|
|
|
|||
|
|
@ -295,13 +295,15 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0720;
|
||||
LastUpgradeCheck = 0800;
|
||||
TargetAttributes = {
|
||||
28F828CB1C4B714D00330CF4 = {
|
||||
CreatedOnToolsVersion = 7.2;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
28F828DF1C4B714D00330CF4 = {
|
||||
CreatedOnToolsVersion = 7.2;
|
||||
LastSwiftMigration = 0800;
|
||||
TestTargetID = 28F828CB1C4B714D00330CF4;
|
||||
};
|
||||
};
|
||||
|
|
@ -441,8 +443,10 @@
|
|||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
|
|
@ -485,8 +489,10 @@
|
|||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
|
|
@ -505,6 +511,7 @@
|
|||
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
};
|
||||
name = Release;
|
||||
|
|
@ -512,29 +519,31 @@
|
|||
28F828EA1C4B714D00330CF4 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/Example/Example/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.Example;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
28F828EB1C4B714D00330CF4 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/Example/Example/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.Example;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
|
@ -547,6 +556,7 @@
|
|||
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.ExampleUITests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 3.0;
|
||||
TEST_TARGET_NAME = Example;
|
||||
USES_XCTRUNNER = YES;
|
||||
};
|
||||
|
|
@ -560,6 +570,7 @@
|
|||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.ExampleUITests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
TEST_TARGET_NAME = Example;
|
||||
USES_XCTRUNNER = YES;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,36 +13,36 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
var window: UIWindow?
|
||||
|
||||
|
||||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
|
||||
UITabBar.appearance().tintColor = UIColor.init(red: 0.027, green: 0.725, blue: 0.608, alpha: 1)
|
||||
UIApplication.sharedApplication().statusBarStyle = .LightContent
|
||||
UIApplication.shared.statusBarStyle = .lightContent
|
||||
|
||||
let _ = YoutubeExampleViewController(nibName: nil, bundle: nil)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func applicationWillResignActive(application: UIApplication) {
|
||||
func applicationWillResignActive(_ application: UIApplication) {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
func applicationDidEnterBackground(application: UIApplication) {
|
||||
func applicationDidEnterBackground(_ application: UIApplication) {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
}
|
||||
|
||||
func applicationWillEnterForeground(application: UIApplication) {
|
||||
func applicationWillEnterForeground(_ application: UIApplication) {
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(application: UIApplication) {
|
||||
func applicationDidBecomeActive(_ application: UIApplication) {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
func applicationWillTerminate(application: UIApplication) {
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class BarExampleViewController: BarPagerTabStripViewController {
|
|||
override func viewDidLoad() {
|
||||
|
||||
// set up style before super view did load is executed
|
||||
settings.style.selectedBarBackgroundColor = .orangeColor()
|
||||
settings.style.selectedBarBackgroundColor = .orange
|
||||
// -
|
||||
|
||||
super.viewDidLoad()
|
||||
|
|
@ -43,11 +43,11 @@ class BarExampleViewController: BarPagerTabStripViewController {
|
|||
|
||||
// MARK: - PagerTabStripDataSource
|
||||
|
||||
override func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
|
||||
let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View")
|
||||
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: "Table View")
|
||||
let child_2 = ChildExampleViewController(itemInfo: "View")
|
||||
let child_3 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 2")
|
||||
let child_3 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 2")
|
||||
let child_4 = ChildExampleViewController(itemInfo: "View 2")
|
||||
|
||||
guard isReload else {
|
||||
|
|
@ -55,24 +55,24 @@ class BarExampleViewController: BarPagerTabStripViewController {
|
|||
}
|
||||
|
||||
var childViewControllers = [child_1, child_2, child_3, child_4]
|
||||
for (index, _) in childViewControllers.enumerate(){
|
||||
for (index, _) in childViewControllers.enumerated(){
|
||||
let nElements = childViewControllers.count - index
|
||||
let n = (Int(arc4random()) % nElements) + index
|
||||
if n != index{
|
||||
swap(&childViewControllers[index], &childViewControllers[n])
|
||||
}
|
||||
}
|
||||
let nItems = 1 + (rand() % 4)
|
||||
let nItems = 1 + (arc4random() % 4)
|
||||
return Array(childViewControllers.prefix(Int(nItems)))
|
||||
}
|
||||
|
||||
override func reloadPagerTabStripView() {
|
||||
isReload = true
|
||||
if rand() % 2 == 0 {
|
||||
pagerBehaviour = .Progressive(skipIntermediateViewControllers: rand() % 2 == 0 , elasticIndicatorLimit: rand() % 2 == 0 )
|
||||
if arc4random() % 2 == 0 {
|
||||
pagerBehaviour = .progressive(skipIntermediateViewControllers: arc4random() % 2 == 0, elasticIndicatorLimit: arc4random() % 2 == 0 )
|
||||
}
|
||||
else {
|
||||
pagerBehaviour = .Common(skipIntermediateViewControllers: rand() % 2 == 0)
|
||||
pagerBehaviour = .common(skipIntermediateViewControllers: arc4random() % 2 == 0)
|
||||
}
|
||||
super.reloadPagerTabStripView()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,20 +32,20 @@ class ButtonBarExampleViewController: ButtonBarPagerTabStripViewController {
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
buttonBarView.selectedBar.backgroundColor = .orangeColor()
|
||||
buttonBarView.selectedBar.backgroundColor = .orange
|
||||
buttonBarView.backgroundColor = UIColor(red: 7/255, green: 185/255, blue: 155/255, alpha: 1)
|
||||
}
|
||||
|
||||
// MARK: - PagerTabStripDataSource
|
||||
|
||||
override func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View")
|
||||
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: "Table View")
|
||||
let child_2 = ChildExampleViewController(itemInfo: "View")
|
||||
let child_3 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 2")
|
||||
let child_3 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 2")
|
||||
let child_4 = ChildExampleViewController(itemInfo: "View 2")
|
||||
let child_5 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View 3")
|
||||
let child_5 = TableChildExampleViewController(style: .plain, itemInfo: "Table View 3")
|
||||
let child_6 = ChildExampleViewController(itemInfo: "View 3")
|
||||
let child_7 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 4")
|
||||
let child_7 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 4")
|
||||
let child_8 = ChildExampleViewController(itemInfo: "View 4")
|
||||
|
||||
guard isReload else {
|
||||
|
|
@ -54,24 +54,24 @@ class ButtonBarExampleViewController: ButtonBarPagerTabStripViewController {
|
|||
|
||||
var childViewControllers = [child_1, child_2, child_3, child_4, child_6, child_7, child_8]
|
||||
|
||||
for (index, _) in childViewControllers.enumerate(){
|
||||
for (index, _) in childViewControllers.enumerated(){
|
||||
let nElements = childViewControllers.count - index
|
||||
let n = (Int(arc4random()) % nElements) + index
|
||||
if n != index{
|
||||
swap(&childViewControllers[index], &childViewControllers[n])
|
||||
}
|
||||
}
|
||||
let nItems = 1 + (rand() % 8)
|
||||
let nItems = 1 + (arc4random() % 8)
|
||||
return Array(childViewControllers.prefix(Int(nItems)))
|
||||
}
|
||||
|
||||
override func reloadPagerTabStripView() {
|
||||
isReload = true
|
||||
if rand() % 2 == 0 {
|
||||
pagerBehaviour = .Progressive(skipIntermediateViewControllers: rand() % 2 == 0 , elasticIndicatorLimit: rand() % 2 == 0 )
|
||||
if arc4random() % 2 == 0 {
|
||||
pagerBehaviour = .progressive(skipIntermediateViewControllers: arc4random() % 2 == 0, elasticIndicatorLimit: arc4random() % 2 == 0 )
|
||||
}
|
||||
else {
|
||||
pagerBehaviour = .Common(skipIntermediateViewControllers: rand() % 2 == 0)
|
||||
pagerBehaviour = .common(skipIntermediateViewControllers: arc4random() % 2 == 0)
|
||||
}
|
||||
super.reloadPagerTabStripView()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,15 +46,15 @@ class ChildExampleViewController: UIViewController, IndicatorInfoProvider {
|
|||
label.text = "XLPagerTabStrip"
|
||||
|
||||
view.addSubview(label)
|
||||
view.backgroundColor = .whiteColor()
|
||||
view.backgroundColor = .white
|
||||
|
||||
view.addConstraint(NSLayoutConstraint(item: label, attribute: .CenterX, relatedBy: .Equal, toItem: view, attribute: .CenterX, multiplier: 1, constant: 0))
|
||||
view.addConstraint(NSLayoutConstraint(item: label, attribute: .CenterY, relatedBy: .Equal, toItem: view, attribute: .CenterY, multiplier: 1, constant: -50))
|
||||
view.addConstraint(NSLayoutConstraint(item: label, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1, constant: 0))
|
||||
view.addConstraint(NSLayoutConstraint(item: label, attribute: .centerY, relatedBy: .equal, toItem: view, attribute: .centerY, multiplier: 1, constant: -50))
|
||||
}
|
||||
|
||||
// MARK: - IndicatorInfoProvider
|
||||
|
||||
func indicatorInfoForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
|
||||
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
|
||||
return itemInfo
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class TableChildExampleViewController: UITableViewController, IndicatorInfoProvi
|
|||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
tableView.registerNib(UINib(nibName: "PostCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: cellIdentifier)
|
||||
tableView.register(UINib(nibName: "PostCell", bundle: Bundle.main), forCellReuseIdentifier: cellIdentifier)
|
||||
tableView.estimatedRowHeight = 60.0;
|
||||
tableView.rowHeight = UITableViewAutomaticDimension
|
||||
tableView.allowsSelection = false
|
||||
|
|
@ -51,24 +51,24 @@ class TableChildExampleViewController: UITableViewController, IndicatorInfoProvi
|
|||
}
|
||||
}
|
||||
|
||||
override func viewWillAppear(animated: Bool) {
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
||||
// MARK: - UITableViewDataSource
|
||||
|
||||
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
|
||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return DataProvider.sharedInstance.postsData.count
|
||||
}
|
||||
|
||||
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
||||
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! PostCell
|
||||
let data = DataProvider.sharedInstance.postsData.objectAtIndex(indexPath.row) as!
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! PostCell
|
||||
let data = DataProvider.sharedInstance.postsData.object(at: indexPath.row) as!
|
||||
NSDictionary
|
||||
cell.configureWithData(data)
|
||||
if blackTheme {
|
||||
|
|
@ -79,7 +79,7 @@ class TableChildExampleViewController: UITableViewController, IndicatorInfoProvi
|
|||
|
||||
// MARK: - IndicatorInfoProvider
|
||||
|
||||
func indicatorInfoForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
|
||||
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
|
||||
return itemInfo
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -37,18 +37,20 @@ class PostCell: UITableViewCell {
|
|||
}
|
||||
|
||||
|
||||
func configureWithData(data: NSDictionary){
|
||||
postName.text = data["post"]!["user"]!!["name"] as? String
|
||||
postText.text = data["post"]!["text"] as? String
|
||||
userImage.image = UIImage(named: postName.text!.stringByReplacingOccurrencesOfString(" ", withString: "_"))
|
||||
func configureWithData(_ data: NSDictionary){
|
||||
if let post = data["post"] as? NSDictionary, let user = post["user"] as? NSDictionary {
|
||||
postName.text = user["name"] as? String
|
||||
postText.text = post["text"] as? String
|
||||
userImage.image = UIImage(named: postName.text!.replacingOccurrences(of: " ", with: "_"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func changeStylToBlack(){
|
||||
userImage?.layer.cornerRadius = 30.0
|
||||
postText.text = nil
|
||||
postName.font = UIFont(name: "HelveticaNeue-Light", size:18) ?? UIFont.systemFontOfSize(18)
|
||||
postName.textColor = .whiteColor()
|
||||
postName.font = UIFont(name: "HelveticaNeue-Light", size:18) ?? .systemFont(ofSize: 18)
|
||||
postName.textColor = .white
|
||||
backgroundColor = UIColor(red: 15/255.0, green: 16/255.0, blue: 16/255.0, alpha: 1.0)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,20 +32,20 @@ class InstagramExampleViewController: ButtonBarPagerTabStripViewController {
|
|||
|
||||
override func viewDidLoad() {
|
||||
// change selected bar color
|
||||
settings.style.buttonBarBackgroundColor = .whiteColor()
|
||||
settings.style.buttonBarItemBackgroundColor = .whiteColor()
|
||||
settings.style.buttonBarBackgroundColor = .white
|
||||
settings.style.buttonBarItemBackgroundColor = .white
|
||||
settings.style.selectedBarBackgroundColor = blueInstagramColor
|
||||
settings.style.buttonBarItemFont = .boldSystemFontOfSize(14)
|
||||
settings.style.buttonBarItemFont = .boldSystemFont(ofSize: 14)
|
||||
settings.style.selectedBarHeight = 2.0
|
||||
settings.style.buttonBarMinimumLineSpacing = 0
|
||||
settings.style.buttonBarItemTitleColor = .blackColor()
|
||||
settings.style.buttonBarItemTitleColor = .black
|
||||
settings.style.buttonBarItemsShouldFillAvailiableWidth = true
|
||||
settings.style.buttonBarLeftContentInset = 0
|
||||
settings.style.buttonBarRightContentInset = 0
|
||||
|
||||
changeCurrentIndexProgressive = { [weak self] (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
|
||||
guard changeCurrentIndex == true else { return }
|
||||
oldCell?.label.textColor = .blackColor()
|
||||
oldCell?.label.textColor = .black
|
||||
newCell?.label.textColor = self?.blueInstagramColor
|
||||
}
|
||||
super.viewDidLoad()
|
||||
|
|
@ -53,16 +53,16 @@ class InstagramExampleViewController: ButtonBarPagerTabStripViewController {
|
|||
|
||||
// MARK: - PagerTabStripDataSource
|
||||
|
||||
override func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "FOLLOWING")
|
||||
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: "FOLLOWING")
|
||||
let child_2 = ChildExampleViewController(itemInfo: "YOU")
|
||||
return [child_1, child_2]
|
||||
}
|
||||
|
||||
// MARK: - Custom Action
|
||||
|
||||
@IBAction func closeAction(sender: UIButton) {
|
||||
dismissViewControllerAnimated(true, completion: nil)
|
||||
@IBAction func closeAction(_ sender: UIButton) {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ class NavButtonBarExampleViewController: ButtonBarPagerTabStripViewController {
|
|||
|
||||
override func viewDidLoad() {
|
||||
// set up style before super view did load is executed
|
||||
settings.style.buttonBarBackgroundColor = .clearColor()
|
||||
settings.style.selectedBarBackgroundColor = .orangeColor()
|
||||
settings.style.buttonBarBackgroundColor = .clear
|
||||
settings.style.selectedBarBackgroundColor = .orange
|
||||
//-
|
||||
super.viewDidLoad()
|
||||
|
||||
|
|
@ -42,31 +42,31 @@ class NavButtonBarExampleViewController: ButtonBarPagerTabStripViewController {
|
|||
guard changeCurrentIndex == true else { return }
|
||||
|
||||
oldCell?.label.textColor = UIColor(white: 1, alpha: 0.6)
|
||||
newCell?.label.textColor = .whiteColor()
|
||||
newCell?.label.textColor = .white
|
||||
|
||||
if animated {
|
||||
UIView.animateWithDuration(0.1, animations: { () -> Void in
|
||||
newCell?.transform = CGAffineTransformMakeScale(1.0, 1.0)
|
||||
oldCell?.transform = CGAffineTransformMakeScale(0.8, 0.8)
|
||||
UIView.animate(withDuration: 0.1, animations: { () -> Void in
|
||||
newCell?.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
|
||||
oldCell?.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
|
||||
})
|
||||
}
|
||||
else {
|
||||
newCell?.transform = CGAffineTransformMakeScale(1.0, 1.0)
|
||||
oldCell?.transform = CGAffineTransformMakeScale(0.8, 0.8)
|
||||
newCell?.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
|
||||
oldCell?.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - PagerTabStripDataSource
|
||||
|
||||
override func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View")
|
||||
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: "Table View")
|
||||
let child_2 = ChildExampleViewController(itemInfo: "View")
|
||||
let child_3 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 2")
|
||||
let child_3 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 2")
|
||||
let child_4 = ChildExampleViewController(itemInfo: "View 1")
|
||||
let child_5 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View 3")
|
||||
let child_5 = TableChildExampleViewController(style: .plain, itemInfo: "Table View 3")
|
||||
let child_6 = ChildExampleViewController(itemInfo: "View 2")
|
||||
let child_7 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 4")
|
||||
let child_7 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 4")
|
||||
let child_8 = ChildExampleViewController(itemInfo: "View 3")
|
||||
|
||||
guard isReload else {
|
||||
|
|
@ -75,30 +75,30 @@ class NavButtonBarExampleViewController: ButtonBarPagerTabStripViewController {
|
|||
|
||||
var childViewControllers = [child_1, child_2, child_3, child_4, child_6, child_7, child_8]
|
||||
|
||||
for (index, _) in childViewControllers.enumerate(){
|
||||
for (index, _) in childViewControllers.enumerated(){
|
||||
let nElements = childViewControllers.count - index
|
||||
let n = (Int(arc4random()) % nElements) + index
|
||||
if n != index{
|
||||
swap(&childViewControllers[index], &childViewControllers[n])
|
||||
}
|
||||
}
|
||||
let nItems = 1 + (rand() % 8)
|
||||
let nItems = 1 + (arc4random() % 8)
|
||||
return Array(childViewControllers.prefix(Int(nItems)))
|
||||
}
|
||||
|
||||
override func reloadPagerTabStripView() {
|
||||
isReload = true
|
||||
if rand() % 2 == 0 {
|
||||
pagerBehaviour = .Progressive(skipIntermediateViewControllers: rand() % 2 == 0 , elasticIndicatorLimit: rand() % 2 == 0 )
|
||||
if arc4random() % 2 == 0 {
|
||||
pagerBehaviour = .progressive(skipIntermediateViewControllers: arc4random() % 2 == 0, elasticIndicatorLimit: arc4random() % 2 == 0 )
|
||||
}
|
||||
else {
|
||||
pagerBehaviour = .Common(skipIntermediateViewControllers: rand() % 2 == 0)
|
||||
pagerBehaviour = .common(skipIntermediateViewControllers: arc4random() % 2 == 0)
|
||||
}
|
||||
super.reloadPagerTabStripView()
|
||||
}
|
||||
|
||||
override func configureCell(cell: ButtonBarViewCell, indicatorInfo: IndicatorInfo) {
|
||||
override func configureCell(_ cell: ButtonBarViewCell, indicatorInfo: IndicatorInfo) {
|
||||
super.configureCell(cell, indicatorInfo: indicatorInfo)
|
||||
cell.backgroundColor = .clearColor()
|
||||
cell.backgroundColor = .clear
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ class ReloadExampleViewController: UIViewController {
|
|||
|
||||
lazy var bigLabel: UILabel = {
|
||||
let bigLabel = UILabel()
|
||||
bigLabel.backgroundColor = .clearColor()
|
||||
bigLabel.textColor = .whiteColor()
|
||||
bigLabel.font = UIFont.boldSystemFontOfSize(20)
|
||||
bigLabel.backgroundColor = .clear
|
||||
bigLabel.textColor = .white
|
||||
bigLabel.font = UIFont.boldSystemFont(ofSize: 20)
|
||||
bigLabel.adjustsFontSizeToFitWidth = true
|
||||
return bigLabel
|
||||
}()
|
||||
|
|
@ -50,28 +50,28 @@ class ReloadExampleViewController: UIViewController {
|
|||
}
|
||||
|
||||
if let pagerViewController = childViewControllers.filter( { $0 is PagerTabStripViewController } ).first as? PagerTabStripViewController {
|
||||
updateTitle(pagerViewController)
|
||||
updateTitle(of: pagerViewController)
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func reloadTapped(sender: UIBarButtonItem) {
|
||||
@IBAction func reloadTapped(_ sender: UIBarButtonItem) {
|
||||
for childViewController in childViewControllers {
|
||||
guard let child = childViewController as? PagerTabStripViewController else {
|
||||
continue
|
||||
}
|
||||
child.reloadPagerTabStripView()
|
||||
updateTitle(child)
|
||||
updateTitle(of: child)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@IBAction func closeTapped(sender: UIButton) {
|
||||
dismissViewControllerAnimated(true, completion: nil)
|
||||
@IBAction func closeTapped(_ sender: UIButton) {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
||||
func updateTitle(pagerTabStripViewController: PagerTabStripViewController) {
|
||||
func stringFromBool(bool: Bool) -> String {
|
||||
func updateTitle(of pagerTabStripViewController: PagerTabStripViewController) {
|
||||
func stringFromBool(_ bool: Bool) -> String {
|
||||
return bool ? "YES" : "NO"
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ class ReloadExampleViewController: UIViewController {
|
|||
navigationItem.titleView?.sizeToFit()
|
||||
}
|
||||
|
||||
override func preferredStatusBarStyle() -> UIStatusBarStyle {
|
||||
return .LightContent
|
||||
override var preferredStatusBarStyle : UIStatusBarStyle {
|
||||
return .lightContent
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,15 +32,15 @@ class SegmentedExampleViewController: SegmentedPagerTabStripViewController {
|
|||
required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
// change segmented style
|
||||
settings.style.segmentedControlColor = .whiteColor()
|
||||
settings.style.segmentedControlColor = .white
|
||||
}
|
||||
|
||||
// MARK: - PagerTabStripDataSource
|
||||
|
||||
override func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View")
|
||||
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: "Table View")
|
||||
let child_2 = ChildExampleViewController(itemInfo: "View")
|
||||
let child_3 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 2")
|
||||
let child_3 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 2")
|
||||
let child_4 = ChildExampleViewController(itemInfo: "View 2")
|
||||
|
||||
guard isReload else {
|
||||
|
|
@ -50,21 +50,20 @@ class SegmentedExampleViewController: SegmentedPagerTabStripViewController {
|
|||
var childViewControllers = [child_1, child_2, child_3, child_4]
|
||||
let count = childViewControllers.count
|
||||
|
||||
for (index, _) in childViewControllers.enumerate(){
|
||||
for (index, _) in childViewControllers.enumerated(){
|
||||
let nElements = count - index
|
||||
let n = (Int(arc4random()) % nElements) + index
|
||||
if n != index{
|
||||
swap(&childViewControllers[index], &childViewControllers[n])
|
||||
}
|
||||
}
|
||||
let nItems = 1 + (rand() % 4)
|
||||
let nItems = 1 + (arc4random() % 4)
|
||||
return Array(childViewControllers.prefix(Int(nItems)))
|
||||
}
|
||||
|
||||
@IBAction func reloadTapped(sender: UIBarButtonItem) {
|
||||
@IBAction func reloadTapped(_ sender: UIBarButtonItem) {
|
||||
isReload = true
|
||||
pagerBehaviour = .Common(skipIntermediateViewControllers: rand() % 2 == 0)
|
||||
pagerBehaviour.skipIntermediateViewControllers
|
||||
pagerBehaviour = .common(skipIntermediateViewControllers: arc4random() % 2 == 0)
|
||||
reloadPagerTabStripView()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,22 +25,22 @@
|
|||
import Foundation
|
||||
import XLPagerTabStrip
|
||||
|
||||
public class SpotifyExampleViewController: ButtonBarPagerTabStripViewController {
|
||||
open class SpotifyExampleViewController: ButtonBarPagerTabStripViewController {
|
||||
|
||||
@IBOutlet weak var shadowView: UIView!
|
||||
|
||||
let graySpotifyColor = UIColor(red: 21/255.0, green: 21/255.0, blue: 24/255.0, alpha: 1.0)
|
||||
let darkGraySpotifyColor = UIColor(red: 19/255.0, green: 20/255.0, blue: 20/255.0, alpha: 1.0)
|
||||
|
||||
public override func viewDidLoad() {
|
||||
open override func viewDidLoad() {
|
||||
// change selected bar color
|
||||
settings.style.buttonBarBackgroundColor = graySpotifyColor
|
||||
settings.style.buttonBarItemBackgroundColor = graySpotifyColor
|
||||
settings.style.selectedBarBackgroundColor = UIColor(red: 33/255.0, green: 174/255.0, blue: 67/255.0, alpha: 1.0)
|
||||
settings.style.buttonBarItemFont = UIFont(name: "HelveticaNeue-Light", size:14) ?? UIFont.systemFontOfSize(14)
|
||||
settings.style.buttonBarItemFont = UIFont(name: "HelveticaNeue-Light", size:14) ?? UIFont.systemFont(ofSize: 14)
|
||||
settings.style.selectedBarHeight = 3.0
|
||||
settings.style.buttonBarMinimumLineSpacing = 0
|
||||
settings.style.buttonBarItemTitleColor = .blackColor()
|
||||
settings.style.buttonBarItemTitleColor = .black
|
||||
settings.style.buttonBarItemsShouldFillAvailiableWidth = true
|
||||
|
||||
settings.style.buttonBarLeftContentInset = 20
|
||||
|
|
@ -49,25 +49,25 @@ public class SpotifyExampleViewController: ButtonBarPagerTabStripViewController
|
|||
changeCurrentIndexProgressive = { (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
|
||||
guard changeCurrentIndex == true else { return }
|
||||
oldCell?.label.textColor = UIColor(red: 138/255.0, green: 138/255.0, blue: 144/255.0, alpha: 1.0)
|
||||
newCell?.label.textColor = .whiteColor()
|
||||
newCell?.label.textColor = .white
|
||||
}
|
||||
super.viewDidLoad()
|
||||
}
|
||||
|
||||
// MARK: - PagerTabStripDataSource
|
||||
|
||||
public override func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: IndicatorInfo(title: "FRIENDS"))
|
||||
open override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: IndicatorInfo(title: "FRIENDS"))
|
||||
child_1.blackTheme = true
|
||||
let child_2 = TableChildExampleViewController(style: .Plain, itemInfo: IndicatorInfo(title: "FEATURED"))
|
||||
let child_2 = TableChildExampleViewController(style: .plain, itemInfo: IndicatorInfo(title: "FEATURED"))
|
||||
child_2.blackTheme = true
|
||||
return [child_1, child_2]
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction func closeAction(sender: UIButton) {
|
||||
dismissViewControllerAnimated(true, completion: nil)
|
||||
@IBAction func closeAction(_ sender: UIButton) {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,15 +28,15 @@ import XLPagerTabStrip
|
|||
class TwitterExampleViewController: TwitterPagerTabStripViewController {
|
||||
var isReload = false
|
||||
|
||||
override func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
|
||||
let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "TableView")
|
||||
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: "TableView")
|
||||
let child_2 = ChildExampleViewController(itemInfo: "View")
|
||||
let child_3 = TableChildExampleViewController(style: .Grouped, itemInfo: "TableView 2")
|
||||
let child_3 = TableChildExampleViewController(style: .grouped, itemInfo: "TableView 2")
|
||||
let child_4 = ChildExampleViewController(itemInfo: "View 2")
|
||||
let child_5 = TableChildExampleViewController(style: .Plain, itemInfo: "TableView 3")
|
||||
let child_5 = TableChildExampleViewController(style: .plain, itemInfo: "TableView 3")
|
||||
let child_6 = ChildExampleViewController(itemInfo: "View 3")
|
||||
let child_7 = TableChildExampleViewController(style: .Grouped, itemInfo: "TableView 4")
|
||||
let child_7 = TableChildExampleViewController(style: .grouped, itemInfo: "TableView 4")
|
||||
let child_8 = ChildExampleViewController(itemInfo: "View 4")
|
||||
|
||||
guard isReload else {
|
||||
|
|
@ -45,18 +45,18 @@ class TwitterExampleViewController: TwitterPagerTabStripViewController {
|
|||
|
||||
var childViewControllers = [child_1, child_2, child_3, child_4, child_6, child_7, child_8]
|
||||
|
||||
for (index, _) in childViewControllers.enumerate(){
|
||||
for (index, _) in childViewControllers.enumerated(){
|
||||
let nElements = childViewControllers.count - index
|
||||
let n = (Int(arc4random()) % nElements) + index
|
||||
if n != index{
|
||||
swap(&childViewControllers[index], &childViewControllers[n])
|
||||
}
|
||||
}
|
||||
let nItems = 1 + (rand() % 8)
|
||||
let nItems = 1 + (arc4random() % 8)
|
||||
return Array(childViewControllers.prefix(Int(nItems)))
|
||||
}
|
||||
|
||||
@IBAction func reloadTapped(sender: AnyObject) {
|
||||
@IBAction func reloadTapped(_ sender: AnyObject) {
|
||||
isReload = true
|
||||
reloadPagerTabStripView()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,14 +31,14 @@ class YoutubeExampleViewController: BaseButtonBarPagerTabStripViewController<You
|
|||
let unselectedIconColor = UIColor(red: 73/255.0, green: 8/255.0, blue: 10/255.0, alpha: 1.0)
|
||||
|
||||
|
||||
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
|
||||
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
|
||||
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
|
||||
buttonBarItemSpec = ButtonBarItemSpec.NibFile(nibName: "YoutubeIconCell", bundle: NSBundle(forClass: YoutubeIconCell.self), width: { (cell: IndicatorInfo) -> CGFloat in
|
||||
buttonBarItemSpec = ButtonBarItemSpec.nibFile(nibName: "YoutubeIconCell", bundle: Bundle(for: YoutubeIconCell.self), width: { (cell: IndicatorInfo) -> CGFloat in
|
||||
return 55.0
|
||||
})
|
||||
}
|
||||
|
|
@ -46,11 +46,11 @@ class YoutubeExampleViewController: BaseButtonBarPagerTabStripViewController<You
|
|||
override func viewDidLoad() {
|
||||
// change selected bar color
|
||||
settings.style.buttonBarBackgroundColor = redColor
|
||||
settings.style.buttonBarItemBackgroundColor = .clearColor()
|
||||
settings.style.buttonBarItemBackgroundColor = .clear
|
||||
settings.style.selectedBarBackgroundColor = UIColor(red: 234/255.0, green: 234/255.0, blue: 234/255.0, alpha: 1.0)
|
||||
settings.style.selectedBarHeight = 4.0
|
||||
settings.style.buttonBarMinimumLineSpacing = 0
|
||||
settings.style.buttonBarItemTitleColor = .blackColor()
|
||||
settings.style.buttonBarItemTitleColor = .black
|
||||
settings.style.buttonBarItemsShouldFillAvailiableWidth = true
|
||||
settings.style.buttonBarLeftContentInset = 0
|
||||
settings.style.buttonBarRightContentInset = 0
|
||||
|
|
@ -60,44 +60,43 @@ class YoutubeExampleViewController: BaseButtonBarPagerTabStripViewController<You
|
|||
changeCurrentIndexProgressive = { [weak self] (oldCell: YoutubeIconCell?, newCell: YoutubeIconCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
|
||||
guard changeCurrentIndex == true else { return }
|
||||
oldCell?.iconImage.tintColor = self?.unselectedIconColor
|
||||
newCell?.iconImage.tintColor = .whiteColor()
|
||||
newCell?.iconImage.tintColor = .white
|
||||
|
||||
}
|
||||
super.viewDidLoad()
|
||||
navigationController?.navigationBar.shadowImage = UIImage()
|
||||
navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
|
||||
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
|
||||
}
|
||||
|
||||
// MARK: - PagerTabStripDataSource
|
||||
|
||||
override func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: IndicatorInfo(title: " HOME", image: UIImage(named: "home")))
|
||||
let child_2 = TableChildExampleViewController(style: .Plain, itemInfo: IndicatorInfo(title: " TRENDING", image: UIImage(named: "trending")))
|
||||
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: IndicatorInfo(title: " HOME", image: UIImage(named: "home")))
|
||||
let child_2 = TableChildExampleViewController(style: .plain, itemInfo: IndicatorInfo(title: " TRENDING", image: UIImage(named: "trending")))
|
||||
let child_3 = ChildExampleViewController(itemInfo: IndicatorInfo(title: " ACCOUNT", image: UIImage(named: "profile")))
|
||||
return [child_1, child_2, child_3]
|
||||
}
|
||||
|
||||
|
||||
override func configureCell(cell: YoutubeIconCell, indicatorInfo: IndicatorInfo) {
|
||||
cell.iconImage.image = indicatorInfo.image?.imageWithRenderingMode(.AlwaysTemplate)
|
||||
override func configure(cell: YoutubeIconCell, for indicatorInfo: IndicatorInfo) {
|
||||
cell.iconImage.image = indicatorInfo.image?.withRenderingMode(.alwaysTemplate)
|
||||
}
|
||||
|
||||
|
||||
override func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
|
||||
super.pagerTabStripViewController(pagerTabStripViewController, updateIndicatorFromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
|
||||
override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
|
||||
super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
|
||||
if indexWasChanged && toIndex > -1 && toIndex < viewControllers.count {
|
||||
let child = viewControllers[toIndex] as! IndicatorInfoProvider
|
||||
UIView.performWithoutAnimation({ [weak self] () -> Void in
|
||||
guard let me = self else { return }
|
||||
me.navigationItem.leftBarButtonItem?.title = child.indicatorInfoForPagerTabStrip(me).title
|
||||
me.navigationItem.leftBarButtonItem?.title = child.indicatorInfo(for: me).title
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction func closeAction(sender: UIButton) {
|
||||
dismissViewControllerAnimated(true, completion: nil)
|
||||
@IBAction func closeAction(_ sender: UIButton) {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
## How to migrate from Swift 2 to Swift 3
|
||||
|
||||
To migrate from Swift 2 to Swift 3 you have to change the naming of some of the functions you call or override. These are the name changes for version 6.0+ in `PagerTabStripViewController`:
|
||||
|
||||
| Swift 2 function name | Swift 3 function name |
|
||||
| --------------------- | --------------------- |
|
||||
| `func viewControllersForPagerTabStrip(_ pagerTabStripController: PagerTabStripViewController) -> [UIViewController]` | `func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController]` |
|
||||
| `func indicatorInfoForPagerTabStrip(_ pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo` | `func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo` |
|
||||
| `func pagerTabStripViewController(_ pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int)` | `func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int)` |
|
||||
| `func pagerTabStripViewController(_ pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool)` | `func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool)` |
|
||||
| `func moveToViewControllerAtIndex(_ index: Int, animated: Bool = true)` | `func moveToViewController(at index: Int, animated: Bool = true)` |
|
||||
| `func moveToViewController(_ viewController: UIViewController, animated: Bool = true)` | `func moveTo(viewController: UIViewController, animated: Bool = true)` |
|
||||
| `func canMoveToIndex(index: Int) -> Bool` | `func canMoveTo(index: Int) -> Bool` |
|
||||
| ` func pageOffsetForChildIndex(index: Int) -> CGFloat` | `func pageOffsetForChild(at index: Int) -> CGFloat` |
|
||||
| `func offsetForChildIndex(_ index: Int) -> CGFloat` | `func offsetForChild(at index: Int) -> CGFloat` |
|
||||
| `func offsetForChildViewController(_ viewController: UIViewController) throws -> CGFloat` | `func offsetForChild(viewController: UIViewController) throws -> CGFloat` |
|
||||
| `func pageForContentOffset(_ contentOffset: CGFloat) -> Int` | `func pageFor(contentOffset: CGFloat) -> Int` |
|
||||
| `func virtualPageForContentOffset(_ contentOffset: CGFloat) -> Int` | `func virtualPageFor(contentOffset: CGFloat) -> Int` |
|
||||
| `func pageForVirtualPage(_ virtualPage: Int) -> Int` | `func pageFor(virtualPage: Int) -> Int` |
|
||||
|
||||
You can check all the changes in [this pull request](https://github.com/xmartlabs/XLPagerTabStrip/pull/226)
|
||||
26
README.md
26
README.md
|
|
@ -100,10 +100,10 @@ For `BarPagerTabStripViewController` we should connect `barView` outlet. barView
|
|||
|
||||
##### Provide the view controllers that will appear embedded into the PagerTabStrip view controller
|
||||
|
||||
You can provide the view controllers by overriding `func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController]` method.
|
||||
You can provide the view controllers by overriding `func viewControllers(for: pagerTabStripController: PagerTabStripViewController) -> [UIViewController]` method.
|
||||
|
||||
```swift
|
||||
override public func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
override public func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
return [MyEmbeddedViewController(), MySecondEmbeddedViewController()]
|
||||
}
|
||||
```
|
||||
|
|
@ -114,13 +114,13 @@ override public func viewControllersForPagerTabStrip(pagerTabStripController: Pa
|
|||
##### Provide information to show in each indicator
|
||||
|
||||
Every UIViewController that will appear within the PagerTabStrip needs to provide either a title or an image.
|
||||
In order to do so they should conform to `IndicatorInfoProvider` by implementing `func indicatorInfoForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo`
|
||||
In order to do so they should conform to `IndicatorInfoProvider` by implementing `func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo`
|
||||
which provides the information required to show the PagerTabStrip menu (indicator) associated with the view controller.
|
||||
|
||||
```swift
|
||||
class MyEmbeddedViewController: UITableViewController, IndicatorInfoProvider {
|
||||
|
||||
func indicatorInfoForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
|
||||
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
|
||||
return IndicatorInfo(title: "My Child title")
|
||||
}
|
||||
}
|
||||
|
|
@ -172,12 +172,12 @@ Normally we don't need to implement these protocols because each pager type alre
|
|||
```swift
|
||||
public protocol PagerTabStripDelegate: class {
|
||||
|
||||
func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int) throws
|
||||
func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int)
|
||||
}
|
||||
|
||||
public protocol PagerTabStripIsProgressiveDelegate : PagerTabStripDelegate {
|
||||
|
||||
func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) throws
|
||||
func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool)
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -319,16 +319,20 @@ github "xmartlabs/XLPagerTabStrip" ~> 5.0
|
|||
|
||||
#### How to change the visible child view controller programmatically
|
||||
|
||||
`XLPagerTabStripViewController` provides the following methods to programmatically change the visible child view controller:
|
||||
`PagerTabStripViewController` provides the following methods to programmatically change the visible child view controller:
|
||||
|
||||
```swift
|
||||
func moveToViewControllerAtIndex(index: Int)
|
||||
func moveToViewControllerAtIndex(index: Int, animated: Bool)
|
||||
func moveToViewController(viewController: UIViewController)
|
||||
func moveToViewController(viewController: UIViewController, animated: Bool)
|
||||
func moveToViewController(at index: Int)
|
||||
func moveToViewController(at index: Int, animated: Bool)
|
||||
func moveTo(viewController: UIViewController)
|
||||
func moveTo(viewController: UIViewController, animated: Bool)
|
||||
```
|
||||
|
||||
|
||||
#### How to migrate from Swift 2 to Swift 3 <a name="migrate"></a>
|
||||
|
||||
Check out [our migration guide](https://github.com/xmartlabs/XLPagerTabStrip/Migration.md)
|
||||
|
||||
## Author
|
||||
|
||||
* [Martin Barreto](https://github.com/mtnBarreto) ([@mtnBarreto](https://twitter.com/mtnBarreto))
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
public struct BarPagerTabStripSettings {
|
||||
|
||||
|
|
@ -35,25 +36,25 @@ public struct BarPagerTabStripSettings {
|
|||
public var style = Style()
|
||||
}
|
||||
|
||||
public class BarPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate {
|
||||
open class BarPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate {
|
||||
|
||||
public var settings = BarPagerTabStripSettings()
|
||||
open var settings = BarPagerTabStripSettings()
|
||||
|
||||
@IBOutlet lazy public var barView: BarView! = { [unowned self] in
|
||||
let barView = BarView(frame: CGRectMake(0, 0, self.view.frame.size.width, self.settings.style.barHeight))
|
||||
barView.autoresizingMask = .FlexibleWidth
|
||||
barView.backgroundColor = .blackColor()
|
||||
barView.selectedBar.backgroundColor = .whiteColor()
|
||||
@IBOutlet lazy open var barView: BarView! = { [unowned self] in
|
||||
let barView = BarView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.settings.style.barHeight))
|
||||
barView.autoresizingMask = .flexibleWidth
|
||||
barView.backgroundColor = .black
|
||||
barView.selectedBar.backgroundColor = .white
|
||||
return barView
|
||||
}()
|
||||
|
||||
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
|
||||
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
|
||||
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
||||
delegate = self
|
||||
datasource = self
|
||||
}
|
||||
|
||||
public override func viewDidLoad() {
|
||||
open override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
barView.backgroundColor = self.settings.style.barBackgroundColor ?? barView.backgroundColor
|
||||
barView.selectedBar.backgroundColor = self.settings.style.selectedBarBackgroundColor ?? barView.selectedBar.backgroundColor
|
||||
|
|
@ -65,30 +66,31 @@ public class BarPagerTabStripViewController: PagerTabStripViewController, PagerT
|
|||
datasource = self
|
||||
}
|
||||
|
||||
public override func viewWillAppear(animated: Bool) {
|
||||
open override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
if barView.superview == nil {
|
||||
view.addSubview(barView)
|
||||
}
|
||||
barView.optionsCount = viewControllers.count
|
||||
barView.moveToIndex(index: currentIndex, animated: false)
|
||||
barView.moveTo(index: currentIndex, animated: false)
|
||||
}
|
||||
|
||||
public override func reloadPagerTabStripView() {
|
||||
open override func reloadPagerTabStripView() {
|
||||
super.reloadPagerTabStripView()
|
||||
barView.optionsCount = viewControllers.count
|
||||
if isViewLoaded(){
|
||||
barView.moveToIndex(index: currentIndex, animated: false)
|
||||
if isViewLoaded{
|
||||
barView.moveTo(index: currentIndex, animated: false)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - PagerTabStripDelegate
|
||||
|
||||
public func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int) {
|
||||
barView.moveToIndex(index: toIndex, animated: true)
|
||||
|
||||
open func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
|
||||
|
||||
barView.move(fromIndex: fromIndex, toIndex: toIndex, progressPercentage: progressPercentage)
|
||||
}
|
||||
|
||||
public func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
|
||||
barView.moveToIndex(fromIndex: fromIndex, toIndex: toIndex, progressPercentage: progressPercentage)
|
||||
|
||||
open func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int) {
|
||||
barView.moveTo(index: toIndex, animated: true)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
public class BarView: UIView {
|
||||
open class BarView: UIView {
|
||||
|
||||
public lazy var selectedBar: UIView = { [unowned self] in
|
||||
let selectedBar = UIView(frame: CGRectMake(0, 0, self.frame.size.width, self.frame.size.height))
|
||||
open lazy var selectedBar: UIView = { [unowned self] in
|
||||
let selectedBar = UIView(frame: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height))
|
||||
return selectedBar
|
||||
}()
|
||||
|
||||
|
|
@ -53,12 +53,12 @@ public class BarView: UIView {
|
|||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func updateSelectedBarPositionWithAnimation(animation: Bool) {
|
||||
private func updateSelectedBarPosition(with animation: Bool) {
|
||||
var frame = selectedBar.frame
|
||||
frame.size.width = self.frame.size.width / CGFloat(optionsCount)
|
||||
frame.origin.x = frame.size.width * CGFloat(selectedIndex)
|
||||
if animation {
|
||||
UIView.animateWithDuration(0.3, animations: { [weak self] in
|
||||
UIView.animate(withDuration: 0.3, animations: { [weak self] in
|
||||
self?.selectedBar.frame = frame
|
||||
})
|
||||
}
|
||||
|
|
@ -67,12 +67,12 @@ public class BarView: UIView {
|
|||
}
|
||||
}
|
||||
|
||||
public func moveToIndex(index index: Int, animated: Bool) {
|
||||
open func moveTo(index: Int, animated: Bool) {
|
||||
selectedIndex = index
|
||||
updateSelectedBarPositionWithAnimation(animated)
|
||||
updateSelectedBarPosition(with: animated)
|
||||
}
|
||||
|
||||
public func moveToIndex(fromIndex fromIndex: Int, toIndex: Int, progressPercentage: CGFloat) {
|
||||
open func move(fromIndex: Int, toIndex: Int, progressPercentage: CGFloat) {
|
||||
selectedIndex = (progressPercentage > 0.5) ? toIndex : fromIndex
|
||||
|
||||
var newFrame = selectedBar.frame
|
||||
|
|
@ -86,8 +86,8 @@ public class BarView: UIView {
|
|||
selectedBar.frame = targetFrame
|
||||
}
|
||||
|
||||
public override func layoutSubviews() {
|
||||
open override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
updateSelectedBarPositionWithAnimation(false)
|
||||
updateSelectedBarPosition(with: false)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,23 +24,23 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
public class BaseButtonBarPagerTabStripViewController<ButtonBarCellType : UICollectionViewCell>: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate, UICollectionViewDelegate, UICollectionViewDataSource {
|
||||
open class BaseButtonBarPagerTabStripViewController<ButtonBarCellType : UICollectionViewCell>: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate, UICollectionViewDelegate, UICollectionViewDataSource {
|
||||
|
||||
public var settings = ButtonBarPagerTabStripSettings()
|
||||
public var buttonBarItemSpec: ButtonBarItemSpec<ButtonBarCellType>!
|
||||
public var changeCurrentIndex: ((oldCell: ButtonBarCellType?, newCell: ButtonBarCellType?, animated: Bool) -> Void)?
|
||||
public var changeCurrentIndexProgressive: ((oldCell: ButtonBarCellType?, newCell: ButtonBarCellType?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void)?
|
||||
open var settings = ButtonBarPagerTabStripSettings()
|
||||
open var buttonBarItemSpec: ButtonBarItemSpec<ButtonBarCellType>!
|
||||
open var changeCurrentIndex: ((_ oldCell: ButtonBarCellType?, _ newCell: ButtonBarCellType?, _ animated: Bool) -> Void)?
|
||||
open var changeCurrentIndexProgressive: ((_ oldCell: ButtonBarCellType?, _ newCell: ButtonBarCellType?, _ progressPercentage: CGFloat, _ changeCurrentIndex: Bool, _ animated: Bool) -> Void)?
|
||||
|
||||
|
||||
@IBOutlet public lazy var buttonBarView: ButtonBarView! = { [unowned self] in
|
||||
@IBOutlet open lazy var buttonBarView: ButtonBarView! = { [unowned self] in
|
||||
var flowLayout = UICollectionViewFlowLayout()
|
||||
flowLayout.scrollDirection = .Horizontal
|
||||
flowLayout.scrollDirection = .horizontal
|
||||
flowLayout.sectionInset = UIEdgeInsetsMake(0, self.settings.style.buttonBarLeftContentInset ?? 35, 0, self.settings.style.buttonBarRightContentInset ?? 35)
|
||||
let buttonBarHeight = self.settings.style.buttonBarHeight ?? 44
|
||||
let buttonBar = ButtonBarView(frame: CGRectMake(0, 0, self.view.frame.size.width, buttonBarHeight), collectionViewLayout: flowLayout)
|
||||
buttonBar.backgroundColor = .orangeColor()
|
||||
buttonBar.selectedBar.backgroundColor = .blackColor()
|
||||
buttonBar.autoresizingMask = .FlexibleWidth
|
||||
let buttonBar = ButtonBarView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: buttonBarHeight), collectionViewLayout: flowLayout)
|
||||
buttonBar.backgroundColor = .orange
|
||||
buttonBar.selectedBar.backgroundColor = .black
|
||||
buttonBar.autoresizingMask = .flexibleWidth
|
||||
var newContainerViewFrame = self.containerView.frame
|
||||
newContainerViewFrame.origin.y = buttonBarHeight
|
||||
newContainerViewFrame.size.height = self.containerView.frame.size.height - (buttonBarHeight - self.containerView.frame.origin.y)
|
||||
|
|
@ -52,7 +52,7 @@ public class BaseButtonBarPagerTabStripViewController<ButtonBarCellType : UIColl
|
|||
return self.calculateWidths()
|
||||
}()
|
||||
|
||||
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
|
||||
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
|
||||
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
||||
delegate = self
|
||||
datasource = self
|
||||
|
|
@ -64,7 +64,7 @@ public class BaseButtonBarPagerTabStripViewController<ButtonBarCellType : UIColl
|
|||
datasource = self
|
||||
}
|
||||
|
||||
public override func viewDidLoad() {
|
||||
open override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
if buttonBarView.superview == nil {
|
||||
|
|
@ -78,38 +78,38 @@ public class BaseButtonBarPagerTabStripViewController<ButtonBarCellType : UIColl
|
|||
}
|
||||
buttonBarView.scrollsToTop = false
|
||||
let flowLayout = buttonBarView.collectionViewLayout as! UICollectionViewFlowLayout
|
||||
flowLayout.scrollDirection = .Horizontal
|
||||
flowLayout.scrollDirection = .horizontal
|
||||
flowLayout.minimumInteritemSpacing = settings.style.buttonBarMinimumLineSpacing ?? flowLayout.minimumLineSpacing
|
||||
flowLayout.minimumLineSpacing = settings.style.buttonBarMinimumLineSpacing ?? flowLayout.minimumLineSpacing
|
||||
let sectionInset = flowLayout.sectionInset
|
||||
flowLayout.sectionInset = UIEdgeInsetsMake(sectionInset.top, self.settings.style.buttonBarLeftContentInset ?? sectionInset.left, sectionInset.bottom, self.settings.style.buttonBarRightContentInset ?? sectionInset.right)
|
||||
buttonBarView.showsHorizontalScrollIndicator = false
|
||||
buttonBarView.backgroundColor = settings.style.buttonBarBackgroundColor ?? buttonBarView.backgroundColor
|
||||
buttonBarView.selectedBar.backgroundColor = settings.style.selectedBarBackgroundColor ?? buttonBarView.selectedBar.backgroundColor
|
||||
buttonBarView.selectedBar.backgroundColor = settings.style.selectedBarBackgroundColor
|
||||
|
||||
buttonBarView.selectedBarHeight = settings.style.selectedBarHeight ?? buttonBarView.selectedBarHeight
|
||||
buttonBarView.selectedBarHeight = settings.style.selectedBarHeight
|
||||
// register button bar item cell
|
||||
switch buttonBarItemSpec! {
|
||||
case .NibFile(let nibName, let bundle, _):
|
||||
buttonBarView.registerNib(UINib(nibName: nibName, bundle: bundle), forCellWithReuseIdentifier:"Cell")
|
||||
case .CellClass:
|
||||
buttonBarView.registerClass(ButtonBarCellType.self, forCellWithReuseIdentifier:"Cell")
|
||||
case .nibFile(let nibName, let bundle, _):
|
||||
buttonBarView.register(UINib(nibName: nibName, bundle: bundle), forCellWithReuseIdentifier:"Cell")
|
||||
case .cellClass:
|
||||
buttonBarView.register(ButtonBarCellType.self, forCellWithReuseIdentifier:"Cell")
|
||||
}
|
||||
//-
|
||||
}
|
||||
|
||||
public override func viewWillAppear(animated: Bool) {
|
||||
open override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
buttonBarView.layoutIfNeeded()
|
||||
isViewAppearing = true
|
||||
}
|
||||
|
||||
public override func viewDidAppear(animated: Bool) {
|
||||
open override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
isViewAppearing = false
|
||||
}
|
||||
|
||||
public override func viewDidLayoutSubviews() {
|
||||
open override func viewDidLayoutSubviews() {
|
||||
super.viewDidLayoutSubviews()
|
||||
|
||||
guard isViewAppearing || isViewRotating else { return }
|
||||
|
|
@ -129,26 +129,26 @@ public class BaseButtonBarPagerTabStripViewController<ButtonBarCellType : UIColl
|
|||
// When the view first appears or is rotated we also need to ensure that the barButtonView's
|
||||
// selectedBar is resized and its contentOffset/scroll is set correctly (the selected
|
||||
// tab/cell may end up either skewed or off screen after a rotation otherwise)
|
||||
buttonBarView.moveToIndex(currentIndex, animated: false, swipeDirection: .None, pagerScroll: .ScrollOnlyIfOutOfScreen)
|
||||
buttonBarView.moveTo(index: currentIndex, animated: false, swipeDirection: .none, pagerScroll: .scrollOnlyIfOutOfScreen)
|
||||
}
|
||||
|
||||
// MARK: - View Rotation
|
||||
|
||||
public override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
|
||||
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
|
||||
open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
||||
super.viewWillTransition(to: size, with: coordinator)
|
||||
}
|
||||
|
||||
// MARK: - Public Methods
|
||||
|
||||
public override func reloadPagerTabStripView() {
|
||||
open override func reloadPagerTabStripView() {
|
||||
super.reloadPagerTabStripView()
|
||||
guard isViewLoaded() else { return }
|
||||
guard isViewLoaded else { return }
|
||||
buttonBarView.reloadData()
|
||||
cachedCellWidths = calculateWidths()
|
||||
buttonBarView.moveToIndex(currentIndex, animated: false, swipeDirection: .None, pagerScroll: .Yes)
|
||||
buttonBarView.moveTo(index: currentIndex, animated: false, swipeDirection: .none, pagerScroll: .yes)
|
||||
}
|
||||
|
||||
public func calculateStretchedCellWidths(minimumCellWidths: [CGFloat], suggestedStretchedCellWidth: CGFloat, previousNumberOfLargeCells: Int) -> CGFloat {
|
||||
open func calculateStretchedCellWidths(_ minimumCellWidths: [CGFloat], suggestedStretchedCellWidth: CGFloat, previousNumberOfLargeCells: Int) -> CGFloat {
|
||||
var numberOfLargeCells = 0
|
||||
var totalWidthOfLargeCells: CGFloat = 0
|
||||
|
||||
|
|
@ -172,80 +172,80 @@ public class BaseButtonBarPagerTabStripViewController<ButtonBarCellType : UIColl
|
|||
return calculateStretchedCellWidths(minimumCellWidths, suggestedStretchedCellWidth: newSuggestedStretchedCellWidth, previousNumberOfLargeCells: numberOfLargeCells)
|
||||
}
|
||||
|
||||
public func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int) {
|
||||
open func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int) {
|
||||
guard shouldUpdateButtonBarView else { return }
|
||||
buttonBarView.moveToIndex(toIndex, animated: true, swipeDirection: toIndex < fromIndex ? .Right : .Left, pagerScroll: .Yes)
|
||||
buttonBarView.moveTo(index: toIndex, animated: true, swipeDirection: toIndex < fromIndex ? .right : .left, pagerScroll: .yes)
|
||||
|
||||
if let changeCurrentIndex = changeCurrentIndex {
|
||||
let oldCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex != fromIndex ? fromIndex : toIndex, inSection: 0)) as? ButtonBarCellType
|
||||
let newCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex, inSection: 0)) as? ButtonBarCellType
|
||||
changeCurrentIndex(oldCell: oldCell, newCell: newCell, animated: true)
|
||||
let oldCell = buttonBarView.cellForItem(at: IndexPath(item: currentIndex != fromIndex ? fromIndex : toIndex, section: 0)) as? ButtonBarCellType
|
||||
let newCell = buttonBarView.cellForItem(at: IndexPath(item: currentIndex, section: 0)) as? ButtonBarCellType
|
||||
changeCurrentIndex(oldCell, newCell, true)
|
||||
}
|
||||
}
|
||||
|
||||
public func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
|
||||
open func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
|
||||
guard shouldUpdateButtonBarView else { return }
|
||||
buttonBarView.moveFromIndex(fromIndex, toIndex: toIndex, progressPercentage: progressPercentage, pagerScroll: .Yes)
|
||||
buttonBarView.move(fromIndex: fromIndex, toIndex: toIndex, progressPercentage: progressPercentage, pagerScroll: .yes)
|
||||
if let changeCurrentIndexProgressive = changeCurrentIndexProgressive {
|
||||
let oldCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex != fromIndex ? fromIndex : toIndex, inSection: 0)) as? ButtonBarCellType
|
||||
let newCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex, inSection: 0)) as? ButtonBarCellType
|
||||
changeCurrentIndexProgressive(oldCell: oldCell, newCell: newCell, progressPercentage: progressPercentage, changeCurrentIndex: indexWasChanged, animated: true)
|
||||
let oldCell = buttonBarView.cellForItem(at: IndexPath(item: currentIndex != fromIndex ? fromIndex : toIndex, section: 0)) as? ButtonBarCellType
|
||||
let newCell = buttonBarView.cellForItem(at: IndexPath(item: currentIndex, section: 0)) as? ButtonBarCellType
|
||||
changeCurrentIndexProgressive(oldCell, newCell, progressPercentage, indexWasChanged, true)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UICollectionViewDelegateFlowLayut
|
||||
|
||||
public func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
|
||||
open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
|
||||
guard let cellWidthValue = cachedCellWidths?[indexPath.row] else {
|
||||
fatalError("cachedCellWidths for \(indexPath.row) must not be nil")
|
||||
}
|
||||
return CGSizeMake(cellWidthValue, collectionView.frame.size.height)
|
||||
return CGSize(width: cellWidthValue, height: collectionView.frame.size.height)
|
||||
}
|
||||
|
||||
public func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
|
||||
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
guard indexPath.item != currentIndex else { return }
|
||||
|
||||
buttonBarView.moveToIndex(indexPath.item, animated: true, swipeDirection: .None, pagerScroll: .Yes)
|
||||
buttonBarView.moveTo(index: indexPath.item, animated: true, swipeDirection: .none, pagerScroll: .yes)
|
||||
shouldUpdateButtonBarView = false
|
||||
|
||||
let oldCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex, inSection: 0)) as? ButtonBarCellType
|
||||
let newCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: indexPath.item, inSection: 0)) as? ButtonBarCellType
|
||||
let oldCell = buttonBarView.cellForItem(at: IndexPath(item: currentIndex, section: 0)) as? ButtonBarCellType
|
||||
let newCell = buttonBarView.cellForItem(at: IndexPath(item: indexPath.item, section: 0)) as? ButtonBarCellType
|
||||
if pagerBehaviour.isProgressiveIndicator {
|
||||
if let changeCurrentIndexProgressive = changeCurrentIndexProgressive {
|
||||
changeCurrentIndexProgressive(oldCell: oldCell, newCell: newCell, progressPercentage: 1, changeCurrentIndex: true, animated: true)
|
||||
changeCurrentIndexProgressive(oldCell, newCell, 1, true, true)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if let changeCurrentIndex = changeCurrentIndex {
|
||||
changeCurrentIndex(oldCell: oldCell, newCell: newCell, animated: true)
|
||||
changeCurrentIndex(oldCell, newCell, true)
|
||||
}
|
||||
}
|
||||
moveToViewControllerAtIndex(indexPath.item)
|
||||
moveToViewController(at: indexPath.item)
|
||||
}
|
||||
|
||||
// MARK: - UICollectionViewDataSource
|
||||
|
||||
public func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
return viewControllers.count
|
||||
}
|
||||
|
||||
public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
|
||||
guard let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as? ButtonBarCellType else {
|
||||
open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as? ButtonBarCellType else {
|
||||
fatalError("UICollectionViewCell should be or extend from ButtonBarViewCell")
|
||||
}
|
||||
let childController = viewControllers[indexPath.item] as! IndicatorInfoProvider
|
||||
let indicatorInfo = childController.indicatorInfoForPagerTabStrip(self)
|
||||
let indicatorInfo = childController.indicatorInfo(for: self)
|
||||
|
||||
configureCell(cell, indicatorInfo: indicatorInfo)
|
||||
configure(cell: cell, for: indicatorInfo)
|
||||
|
||||
if pagerBehaviour.isProgressiveIndicator {
|
||||
if let changeCurrentIndexProgressive = changeCurrentIndexProgressive {
|
||||
changeCurrentIndexProgressive(oldCell: currentIndex == indexPath.item ? nil : cell, newCell: currentIndex == indexPath.item ? cell : nil, progressPercentage: 1, changeCurrentIndex: true, animated: false)
|
||||
changeCurrentIndexProgressive(currentIndex == indexPath.item ? nil : cell, currentIndex == indexPath.item ? cell : nil, 1, true, false)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if let changeCurrentIndex = changeCurrentIndex {
|
||||
changeCurrentIndex(oldCell: currentIndex == indexPath.item ? nil : cell, newCell: currentIndex == indexPath.item ? cell : nil, animated: false)
|
||||
changeCurrentIndex(currentIndex == indexPath.item ? nil : cell, currentIndex == indexPath.item ? cell : nil, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -254,14 +254,14 @@ public class BaseButtonBarPagerTabStripViewController<ButtonBarCellType : UIColl
|
|||
|
||||
// MARK: - UIScrollViewDelegate
|
||||
|
||||
public override func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
|
||||
open override func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
|
||||
super.scrollViewDidEndScrollingAnimation(scrollView)
|
||||
|
||||
guard scrollView == containerView else { return }
|
||||
shouldUpdateButtonBarView = true
|
||||
}
|
||||
|
||||
public func configureCell(cell: ButtonBarCellType, indicatorInfo: IndicatorInfo){
|
||||
open func configure(cell: ButtonBarCellType, for indicatorInfo: IndicatorInfo){
|
||||
fatalError("You must override this method to set up ButtonBarView cell accordingly")
|
||||
}
|
||||
|
||||
|
|
@ -274,13 +274,13 @@ public class BaseButtonBarPagerTabStripViewController<ButtonBarCellType : UIColl
|
|||
|
||||
for viewController in self.viewControllers {
|
||||
let childController = viewController as! IndicatorInfoProvider
|
||||
let indicatorInfo = childController.indicatorInfoForPagerTabStrip(self)
|
||||
let indicatorInfo = childController.indicatorInfo(for: self)
|
||||
switch buttonBarItemSpec! {
|
||||
case .CellClass(let widthCallback):
|
||||
case .cellClass(let widthCallback):
|
||||
let width = widthCallback(indicatorInfo)
|
||||
minimumCellWidths.append(width)
|
||||
collectionViewContentWidth += width
|
||||
case .NibFile(_, _, let widthCallback):
|
||||
case .nibFile(_, _, let widthCallback):
|
||||
let width = widthCallback(indicatorInfo)
|
||||
minimumCellWidths.append(width)
|
||||
collectionViewContentWidth += width
|
||||
|
|
@ -313,9 +313,9 @@ public class BaseButtonBarPagerTabStripViewController<ButtonBarCellType : UIColl
|
|||
}
|
||||
|
||||
|
||||
public class ExampleBaseButtonBarPagerTabStripViewController: BaseButtonBarPagerTabStripViewController<ButtonBarViewCell> {
|
||||
open class ExampleBaseButtonBarPagerTabStripViewController: BaseButtonBarPagerTabStripViewController<ButtonBarViewCell> {
|
||||
|
||||
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
|
||||
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
|
||||
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
||||
initialize()
|
||||
}
|
||||
|
|
@ -325,18 +325,18 @@ public class ExampleBaseButtonBarPagerTabStripViewController: BaseButtonBarPager
|
|||
initialize()
|
||||
}
|
||||
|
||||
public func initialize(){
|
||||
buttonBarItemSpec = .NibFile(nibName: "ButtonCell", bundle: NSBundle(forClass: ButtonBarViewCell.self), width:{ [weak self] (childItemInfo) -> CGFloat in
|
||||
open func initialize(){
|
||||
buttonBarItemSpec = .nibFile(nibName: "ButtonCell", bundle: Bundle(for: ButtonBarViewCell.self), width:{ [weak self] (childItemInfo) -> CGFloat in
|
||||
let label = UILabel()
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
label.font = self?.settings.style.buttonBarItemFont ?? label.font
|
||||
label.text = childItemInfo.title
|
||||
let labelSize = label.intrinsicContentSize()
|
||||
let labelSize = label.intrinsicContentSize
|
||||
return labelSize.width + CGFloat(self?.settings.style.buttonBarItemLeftRightMargin ?? 8 * 2)
|
||||
})
|
||||
}
|
||||
|
||||
public override func configureCell(cell: ButtonBarViewCell, indicatorInfo: IndicatorInfo){
|
||||
open override func configure(cell: ButtonBarViewCell, for indicatorInfo: IndicatorInfo){
|
||||
cell.label.text = indicatorInfo.title
|
||||
if let image = indicatorInfo.image {
|
||||
cell.imageView.image = image
|
||||
|
|
|
|||
|
|
@ -26,14 +26,14 @@ import Foundation
|
|||
|
||||
public enum ButtonBarItemSpec<CellType: UICollectionViewCell> {
|
||||
|
||||
case NibFile(nibName: String, bundle: NSBundle?, width:((IndicatorInfo)-> CGFloat))
|
||||
case CellClass(width:((IndicatorInfo)-> CGFloat))
|
||||
case nibFile(nibName: String, bundle: Bundle?, width:((IndicatorInfo)-> CGFloat))
|
||||
case cellClass(width:((IndicatorInfo)-> CGFloat))
|
||||
|
||||
public var weight: ((IndicatorInfo) -> CGFloat) {
|
||||
switch self {
|
||||
case .CellClass(let widthCallback):
|
||||
case .cellClass(let widthCallback):
|
||||
return widthCallback
|
||||
case .NibFile(_, _, let widthCallback):
|
||||
case .nibFile(_, _, let widthCallback):
|
||||
return widthCallback
|
||||
}
|
||||
}
|
||||
|
|
@ -43,16 +43,16 @@ public struct ButtonBarPagerTabStripSettings {
|
|||
|
||||
public struct Style {
|
||||
public var buttonBarBackgroundColor: UIColor?
|
||||
@available(*, deprecated=4.0.2) public var buttonBarMinimumInteritemSpacing: CGFloat? = 0
|
||||
@available(*, deprecated: 4.0.2) public var buttonBarMinimumInteritemSpacing: CGFloat? = 0
|
||||
public var buttonBarMinimumLineSpacing: CGFloat?
|
||||
public var buttonBarLeftContentInset: CGFloat?
|
||||
public var buttonBarRightContentInset: CGFloat?
|
||||
|
||||
public var selectedBarBackgroundColor = UIColor.blackColor()
|
||||
public var selectedBarBackgroundColor = UIColor.black
|
||||
public var selectedBarHeight: CGFloat = 5
|
||||
|
||||
public var buttonBarItemBackgroundColor: UIColor?
|
||||
public var buttonBarItemFont = UIFont.systemFontOfSize(18)
|
||||
public var buttonBarItemFont = UIFont.systemFont(ofSize: 18)
|
||||
public var buttonBarItemLeftRightMargin: CGFloat = 8
|
||||
public var buttonBarItemTitleColor: UIColor?
|
||||
public var buttonBarItemsShouldFillAvailiableWidth = true
|
||||
|
|
@ -64,30 +64,30 @@ public struct ButtonBarPagerTabStripSettings {
|
|||
public var style = Style()
|
||||
}
|
||||
|
||||
public class ButtonBarPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate, UICollectionViewDelegate, UICollectionViewDataSource {
|
||||
open class ButtonBarPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate, UICollectionViewDelegate, UICollectionViewDataSource {
|
||||
|
||||
public var settings = ButtonBarPagerTabStripSettings()
|
||||
open var settings = ButtonBarPagerTabStripSettings()
|
||||
|
||||
lazy public var buttonBarItemSpec: ButtonBarItemSpec<ButtonBarViewCell> = .NibFile(nibName: "ButtonCell", bundle: NSBundle(forClass: ButtonBarViewCell.self), width:{ [weak self] (childItemInfo) -> CGFloat in
|
||||
lazy open var buttonBarItemSpec: ButtonBarItemSpec<ButtonBarViewCell> = .nibFile(nibName: "ButtonCell", bundle: Bundle(for: ButtonBarViewCell.self), width:{ [weak self] (childItemInfo) -> CGFloat in
|
||||
let label = UILabel()
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
label.font = self?.settings.style.buttonBarItemFont
|
||||
label.text = childItemInfo.title
|
||||
let labelSize = label.intrinsicContentSize()
|
||||
let labelSize = label.intrinsicContentSize
|
||||
return labelSize.width + (self?.settings.style.buttonBarItemLeftRightMargin ?? 8) * 2
|
||||
})
|
||||
|
||||
public var changeCurrentIndex: ((oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, animated: Bool) -> Void)?
|
||||
public var changeCurrentIndexProgressive: ((oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void)?
|
||||
open var changeCurrentIndex: ((_ oldCell: ButtonBarViewCell?, _ newCell: ButtonBarViewCell?, _ animated: Bool) -> Void)?
|
||||
open var changeCurrentIndexProgressive: ((_ oldCell: ButtonBarViewCell?, _ newCell: ButtonBarViewCell?, _ progressPercentage: CGFloat, _ changeCurrentIndex: Bool, _ animated: Bool) -> Void)?
|
||||
|
||||
@IBOutlet public lazy var buttonBarView: ButtonBarView! = { [unowned self] in
|
||||
@IBOutlet open lazy var buttonBarView: ButtonBarView! = { [unowned self] in
|
||||
var flowLayout = UICollectionViewFlowLayout()
|
||||
flowLayout.scrollDirection = .Horizontal
|
||||
flowLayout.scrollDirection = .horizontal
|
||||
let buttonBarHeight = self.settings.style.buttonBarHeight ?? 44
|
||||
let buttonBar = ButtonBarView(frame: CGRectMake(0, 0, self.view.frame.size.width, buttonBarHeight), collectionViewLayout: flowLayout)
|
||||
buttonBar.backgroundColor = .orangeColor()
|
||||
buttonBar.selectedBar.backgroundColor = .blackColor()
|
||||
buttonBar.autoresizingMask = .FlexibleWidth
|
||||
let buttonBar = ButtonBarView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: buttonBarHeight), collectionViewLayout: flowLayout)
|
||||
buttonBar.backgroundColor = .orange
|
||||
buttonBar.selectedBar.backgroundColor = .black
|
||||
buttonBar.autoresizingMask = .flexibleWidth
|
||||
var newContainerViewFrame = self.containerView.frame
|
||||
newContainerViewFrame.origin.y = buttonBarHeight
|
||||
newContainerViewFrame.size.height = self.containerView.frame.size.height - (buttonBarHeight - self.containerView.frame.origin.y)
|
||||
|
|
@ -99,7 +99,7 @@ public class ButtonBarPagerTabStripViewController: PagerTabStripViewController,
|
|||
return self.calculateWidths()
|
||||
}()
|
||||
|
||||
override public init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
|
||||
override public init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
|
||||
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
||||
delegate = self
|
||||
datasource = self
|
||||
|
|
@ -111,7 +111,7 @@ public class ButtonBarPagerTabStripViewController: PagerTabStripViewController,
|
|||
datasource = self
|
||||
}
|
||||
|
||||
public override func viewDidLoad() {
|
||||
open override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
if buttonBarView.superview == nil {
|
||||
|
|
@ -125,7 +125,7 @@ public class ButtonBarPagerTabStripViewController: PagerTabStripViewController,
|
|||
}
|
||||
buttonBarView.scrollsToTop = false
|
||||
let flowLayout = buttonBarView.collectionViewLayout as! UICollectionViewFlowLayout
|
||||
flowLayout.scrollDirection = .Horizontal
|
||||
flowLayout.scrollDirection = .horizontal
|
||||
flowLayout.minimumInteritemSpacing = 0
|
||||
flowLayout.minimumLineSpacing = settings.style.buttonBarMinimumLineSpacing ?? flowLayout.minimumLineSpacing
|
||||
let sectionInset = flowLayout.sectionInset
|
||||
|
|
@ -135,23 +135,23 @@ public class ButtonBarPagerTabStripViewController: PagerTabStripViewController,
|
|||
buttonBarView.backgroundColor = settings.style.buttonBarBackgroundColor ?? buttonBarView.backgroundColor
|
||||
buttonBarView.selectedBar.backgroundColor = settings.style.selectedBarBackgroundColor
|
||||
|
||||
buttonBarView.selectedBarHeight = settings.style.selectedBarHeight ?? buttonBarView.selectedBarHeight
|
||||
buttonBarView.selectedBarHeight = settings.style.selectedBarHeight
|
||||
// register button bar item cell
|
||||
switch buttonBarItemSpec {
|
||||
case .NibFile(let nibName, let bundle, _):
|
||||
buttonBarView.registerNib(UINib(nibName: nibName, bundle: bundle), forCellWithReuseIdentifier:"Cell")
|
||||
case .CellClass:
|
||||
buttonBarView.registerClass(ButtonBarViewCell.self, forCellWithReuseIdentifier:"Cell")
|
||||
case .nibFile(let nibName, let bundle, _):
|
||||
buttonBarView.register(UINib(nibName: nibName, bundle: bundle), forCellWithReuseIdentifier:"Cell")
|
||||
case .cellClass:
|
||||
buttonBarView.register(ButtonBarViewCell.self, forCellWithReuseIdentifier:"Cell")
|
||||
}
|
||||
//-
|
||||
}
|
||||
|
||||
public override func viewWillAppear(animated: Bool) {
|
||||
open override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
buttonBarView.layoutIfNeeded()
|
||||
}
|
||||
|
||||
public override func viewDidLayoutSubviews() {
|
||||
open override func viewDidLayoutSubviews() {
|
||||
super.viewDidLayoutSubviews()
|
||||
|
||||
guard isViewAppearing || isViewRotating else { return }
|
||||
|
|
@ -171,20 +171,20 @@ public class ButtonBarPagerTabStripViewController: PagerTabStripViewController,
|
|||
// When the view first appears or is rotated we also need to ensure that the barButtonView's
|
||||
// selectedBar is resized and its contentOffset/scroll is set correctly (the selected
|
||||
// tab/cell may end up either skewed or off screen after a rotation otherwise)
|
||||
buttonBarView.moveToIndex(currentIndex, animated: false, swipeDirection: .None, pagerScroll: .ScrollOnlyIfOutOfScreen)
|
||||
buttonBarView.moveTo(index: currentIndex, animated: false, swipeDirection: .none, pagerScroll: .scrollOnlyIfOutOfScreen)
|
||||
}
|
||||
|
||||
// MARK: - Public Methods
|
||||
|
||||
public override func reloadPagerTabStripView() {
|
||||
open override func reloadPagerTabStripView() {
|
||||
super.reloadPagerTabStripView()
|
||||
guard isViewLoaded() else { return }
|
||||
guard isViewLoaded else { return }
|
||||
buttonBarView.reloadData()
|
||||
cachedCellWidths = calculateWidths()
|
||||
buttonBarView.moveToIndex(currentIndex, animated: false, swipeDirection: .None, pagerScroll: .Yes)
|
||||
buttonBarView.moveTo(index: currentIndex, animated: false, swipeDirection: .none, pagerScroll: .yes)
|
||||
}
|
||||
|
||||
public func calculateStretchedCellWidths(minimumCellWidths: [CGFloat], suggestedStretchedCellWidth: CGFloat, previousNumberOfLargeCells: Int) -> CGFloat {
|
||||
open func calculateStretchedCellWidths(_ minimumCellWidths: [CGFloat], suggestedStretchedCellWidth: CGFloat, previousNumberOfLargeCells: Int) -> CGFloat {
|
||||
var numberOfLargeCells = 0
|
||||
var totalWidthOfLargeCells: CGFloat = 0
|
||||
|
||||
|
|
@ -205,73 +205,73 @@ public class ButtonBarPagerTabStripViewController: PagerTabStripViewController,
|
|||
|
||||
return calculateStretchedCellWidths(minimumCellWidths, suggestedStretchedCellWidth: newSuggestedStretchedCellWidth, previousNumberOfLargeCells: numberOfLargeCells)
|
||||
}
|
||||
|
||||
public func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int) {
|
||||
|
||||
open func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int) {
|
||||
guard shouldUpdateButtonBarView else { return }
|
||||
buttonBarView.moveToIndex(toIndex, animated: true, swipeDirection: toIndex < fromIndex ? .Right : .Left, pagerScroll: .Yes)
|
||||
buttonBarView.moveTo(index: toIndex, animated: true, swipeDirection: toIndex < fromIndex ? .right : .left, pagerScroll: .yes)
|
||||
|
||||
if let changeCurrentIndex = changeCurrentIndex {
|
||||
let oldCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex != fromIndex ? fromIndex : toIndex, inSection: 0)) as? ButtonBarViewCell
|
||||
let newCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex, inSection: 0)) as? ButtonBarViewCell
|
||||
changeCurrentIndex(oldCell: oldCell, newCell: newCell, animated: true)
|
||||
let oldCell = buttonBarView.cellForItem(at: IndexPath(item: currentIndex != fromIndex ? fromIndex : toIndex, section: 0)) as? ButtonBarViewCell
|
||||
let newCell = buttonBarView.cellForItem(at: IndexPath(item: currentIndex, section: 0)) as? ButtonBarViewCell
|
||||
changeCurrentIndex(oldCell, newCell, true)
|
||||
}
|
||||
}
|
||||
|
||||
public func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
|
||||
|
||||
open func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
|
||||
guard shouldUpdateButtonBarView else { return }
|
||||
buttonBarView.moveFromIndex(fromIndex, toIndex: toIndex, progressPercentage: progressPercentage, pagerScroll: .Yes)
|
||||
buttonBarView.move(fromIndex: fromIndex, toIndex: toIndex, progressPercentage: progressPercentage, pagerScroll: .yes)
|
||||
if let changeCurrentIndexProgressive = changeCurrentIndexProgressive {
|
||||
let oldCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex != fromIndex ? fromIndex : toIndex, inSection: 0)) as? ButtonBarViewCell
|
||||
let newCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex, inSection: 0)) as? ButtonBarViewCell
|
||||
changeCurrentIndexProgressive(oldCell: oldCell, newCell: newCell, progressPercentage: progressPercentage, changeCurrentIndex: indexWasChanged, animated: true)
|
||||
let oldCell = buttonBarView.cellForItem(at: IndexPath(item: currentIndex != fromIndex ? fromIndex : toIndex, section: 0)) as? ButtonBarViewCell
|
||||
let newCell = buttonBarView.cellForItem(at: IndexPath(item: currentIndex, section: 0)) as? ButtonBarViewCell
|
||||
changeCurrentIndexProgressive(oldCell, newCell, progressPercentage, indexWasChanged, true)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UICollectionViewDelegateFlowLayut
|
||||
|
||||
public func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
|
||||
open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
|
||||
guard let cellWidthValue = cachedCellWidths?[indexPath.row] else {
|
||||
fatalError("cachedCellWidths for \(indexPath.row) must not be nil")
|
||||
}
|
||||
return CGSizeMake(cellWidthValue, collectionView.frame.size.height)
|
||||
return CGSize(width: cellWidthValue, height: collectionView.frame.size.height)
|
||||
}
|
||||
|
||||
public func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
|
||||
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
guard indexPath.item != currentIndex else { return }
|
||||
|
||||
buttonBarView.moveToIndex(indexPath.item, animated: true, swipeDirection: .None, pagerScroll: .Yes)
|
||||
buttonBarView.moveTo(index: indexPath.item, animated: true, swipeDirection: .none, pagerScroll: .yes)
|
||||
shouldUpdateButtonBarView = false
|
||||
|
||||
let oldCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: currentIndex, inSection: 0)) as? ButtonBarViewCell
|
||||
let newCell = buttonBarView.cellForItemAtIndexPath(NSIndexPath(forItem: indexPath.item, inSection: 0)) as? ButtonBarViewCell
|
||||
let oldCell = buttonBarView.cellForItem(at: IndexPath(item: currentIndex, section: 0)) as? ButtonBarViewCell
|
||||
let newCell = buttonBarView.cellForItem(at: IndexPath(item: indexPath.item, section: 0)) as? ButtonBarViewCell
|
||||
if pagerBehaviour.isProgressiveIndicator {
|
||||
if let changeCurrentIndexProgressive = changeCurrentIndexProgressive {
|
||||
changeCurrentIndexProgressive(oldCell: oldCell, newCell: newCell, progressPercentage: 1, changeCurrentIndex: true, animated: true)
|
||||
changeCurrentIndexProgressive(oldCell, newCell, 1, true, true)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if let changeCurrentIndex = changeCurrentIndex {
|
||||
changeCurrentIndex(oldCell: oldCell, newCell: newCell, animated: true)
|
||||
changeCurrentIndex(oldCell, newCell, true)
|
||||
}
|
||||
}
|
||||
moveToViewControllerAtIndex(indexPath.item)
|
||||
moveToViewController(at: indexPath.item)
|
||||
}
|
||||
|
||||
// MARK: - UICollectionViewDataSource
|
||||
|
||||
public func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
return viewControllers.count
|
||||
}
|
||||
|
||||
public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
|
||||
guard let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as? ButtonBarViewCell else {
|
||||
open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as? ButtonBarViewCell else {
|
||||
fatalError("UICollectionViewCell should be or extend from ButtonBarViewCell")
|
||||
}
|
||||
let childController = viewControllers[indexPath.item] as! IndicatorInfoProvider
|
||||
let indicatorInfo = childController.indicatorInfoForPagerTabStrip(self)
|
||||
let indicatorInfo = childController.indicatorInfo(for: self)
|
||||
|
||||
cell.label.text = indicatorInfo.title
|
||||
cell.label.font = settings.style.buttonBarItemFont ?? cell.label.font
|
||||
cell.label.font = settings.style.buttonBarItemFont
|
||||
cell.label.textColor = settings.style.buttonBarItemTitleColor ?? cell.label.textColor
|
||||
cell.contentView.backgroundColor = settings.style.buttonBarItemBackgroundColor ?? cell.contentView.backgroundColor
|
||||
cell.backgroundColor = settings.style.buttonBarItemBackgroundColor ?? cell.backgroundColor
|
||||
|
|
@ -286,12 +286,12 @@ public class ButtonBarPagerTabStripViewController: PagerTabStripViewController,
|
|||
|
||||
if pagerBehaviour.isProgressiveIndicator {
|
||||
if let changeCurrentIndexProgressive = changeCurrentIndexProgressive {
|
||||
changeCurrentIndexProgressive(oldCell: currentIndex == indexPath.item ? nil : cell, newCell: currentIndex == indexPath.item ? cell : nil, progressPercentage: 1, changeCurrentIndex: true, animated: false)
|
||||
changeCurrentIndexProgressive(currentIndex == indexPath.item ? nil : cell, currentIndex == indexPath.item ? cell : nil, 1, true, false)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if let changeCurrentIndex = changeCurrentIndex {
|
||||
changeCurrentIndex(oldCell: currentIndex == indexPath.item ? nil : cell, newCell: currentIndex == indexPath.item ? cell : nil, animated: false)
|
||||
changeCurrentIndex(currentIndex == indexPath.item ? nil : cell, currentIndex == indexPath.item ? cell : nil, false)
|
||||
}
|
||||
}
|
||||
return cell
|
||||
|
|
@ -299,14 +299,14 @@ public class ButtonBarPagerTabStripViewController: PagerTabStripViewController,
|
|||
|
||||
// MARK: - UIScrollViewDelegate
|
||||
|
||||
public override func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
|
||||
open override func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
|
||||
super.scrollViewDidEndScrollingAnimation(scrollView)
|
||||
|
||||
guard scrollView == containerView else { return }
|
||||
shouldUpdateButtonBarView = true
|
||||
}
|
||||
|
||||
public func configureCell(cell: ButtonBarViewCell, indicatorInfo: IndicatorInfo){
|
||||
open func configureCell(_ cell: ButtonBarViewCell, indicatorInfo: IndicatorInfo){
|
||||
}
|
||||
|
||||
private func calculateWidths() -> [CGFloat] {
|
||||
|
|
@ -318,13 +318,13 @@ public class ButtonBarPagerTabStripViewController: PagerTabStripViewController,
|
|||
|
||||
for viewController in self.viewControllers {
|
||||
let childController = viewController as! IndicatorInfoProvider
|
||||
let indicatorInfo = childController.indicatorInfoForPagerTabStrip(self)
|
||||
let indicatorInfo = childController.indicatorInfo(for: self)
|
||||
switch buttonBarItemSpec {
|
||||
case .CellClass(let widthCallback):
|
||||
case .cellClass(let widthCallback):
|
||||
let width = widthCallback(indicatorInfo)
|
||||
minimumCellWidths.append(width)
|
||||
collectionViewContentWidth += width
|
||||
case .NibFile(_, _, let widthCallback):
|
||||
case .nibFile(_, _, let widthCallback):
|
||||
let width = widthCallback(indicatorInfo)
|
||||
minimumCellWidths.append(width)
|
||||
collectionViewContentWidth += width
|
||||
|
|
|
|||
|
|
@ -25,22 +25,22 @@
|
|||
import UIKit
|
||||
|
||||
public enum PagerScroll {
|
||||
case No
|
||||
case Yes
|
||||
case ScrollOnlyIfOutOfScreen
|
||||
case no
|
||||
case yes
|
||||
case scrollOnlyIfOutOfScreen
|
||||
}
|
||||
|
||||
public enum SelectedBarAlignment {
|
||||
case Left
|
||||
case Center
|
||||
case Right
|
||||
case Progressive
|
||||
case left
|
||||
case center
|
||||
case right
|
||||
case progressive
|
||||
}
|
||||
|
||||
public class ButtonBarView: UICollectionView {
|
||||
open class ButtonBarView: UICollectionView {
|
||||
|
||||
public lazy var selectedBar: UIView = { [unowned self] in
|
||||
let bar = UIView(frame: CGRectMake(0, self.frame.size.height - CGFloat(self.selectedBarHeight), 0, CGFloat(self.selectedBarHeight)))
|
||||
open lazy var selectedBar: UIView = { [unowned self] in
|
||||
let bar = UIView(frame: CGRect(x: 0, y: self.frame.size.height - CGFloat(self.selectedBarHeight), width: 0, height: CGFloat(self.selectedBarHeight)))
|
||||
bar.layer.zPosition = 9999
|
||||
return bar
|
||||
}()
|
||||
|
|
@ -50,7 +50,7 @@ public class ButtonBarView: UICollectionView {
|
|||
self.updateSlectedBarYPosition()
|
||||
}
|
||||
}
|
||||
var selectedBarAlignment: SelectedBarAlignment = .Center
|
||||
var selectedBarAlignment: SelectedBarAlignment = .center
|
||||
var selectedIndex = 0
|
||||
|
||||
required public init?(coder aDecoder: NSCoder) {
|
||||
|
|
@ -63,31 +63,31 @@ public class ButtonBarView: UICollectionView {
|
|||
addSubview(selectedBar)
|
||||
}
|
||||
|
||||
public func moveToIndex(toIndex: Int, animated: Bool, swipeDirection: SwipeDirection, pagerScroll: PagerScroll) {
|
||||
selectedIndex = toIndex
|
||||
open func moveTo(index: Int, animated: Bool, swipeDirection: SwipeDirection, pagerScroll: PagerScroll) {
|
||||
selectedIndex = index
|
||||
updateSelectedBarPosition(animated, swipeDirection: swipeDirection, pagerScroll: pagerScroll)
|
||||
}
|
||||
|
||||
public func moveFromIndex(fromIndex: Int, toIndex: Int, progressPercentage: CGFloat,pagerScroll: PagerScroll) {
|
||||
open func move(fromIndex: Int, toIndex: Int, progressPercentage: CGFloat,pagerScroll: PagerScroll) {
|
||||
selectedIndex = progressPercentage > 0.5 ? toIndex : fromIndex
|
||||
|
||||
let fromFrame = layoutAttributesForItemAtIndexPath(NSIndexPath(forItem: fromIndex, inSection: 0))!.frame
|
||||
let fromFrame = layoutAttributesForItem(at: IndexPath(item: fromIndex, section: 0))!.frame
|
||||
let numberOfItems = dataSource!.collectionView(self, numberOfItemsInSection: 0)
|
||||
|
||||
var toFrame: CGRect
|
||||
|
||||
if toIndex < 0 || toIndex > numberOfItems - 1 {
|
||||
if toIndex < 0 {
|
||||
let cellAtts = layoutAttributesForItemAtIndexPath(NSIndexPath(forItem: 0, inSection: 0))
|
||||
toFrame = CGRectOffset(cellAtts!.frame, -cellAtts!.frame.size.width, 0)
|
||||
let cellAtts = layoutAttributesForItem(at: IndexPath(item: 0, section: 0))
|
||||
toFrame = cellAtts!.frame.offsetBy(dx: -cellAtts!.frame.size.width, dy: 0)
|
||||
}
|
||||
else {
|
||||
let cellAtts = layoutAttributesForItemAtIndexPath(NSIndexPath(forItem: (numberOfItems - 1), inSection: 0))
|
||||
toFrame = CGRectOffset(cellAtts!.frame, cellAtts!.frame.size.width, 0)
|
||||
let cellAtts = layoutAttributesForItem(at: IndexPath(item: (numberOfItems - 1), section: 0))
|
||||
toFrame = cellAtts!.frame.offsetBy(dx: cellAtts!.frame.size.width, dy: 0)
|
||||
}
|
||||
}
|
||||
else {
|
||||
toFrame = layoutAttributesForItemAtIndexPath(NSIndexPath(forItem: toIndex, inSection: 0))!.frame
|
||||
toFrame = layoutAttributesForItem(at: IndexPath(item: toIndex, section: 0))!.frame
|
||||
}
|
||||
|
||||
var targetFrame = fromFrame
|
||||
|
|
@ -95,7 +95,7 @@ public class ButtonBarView: UICollectionView {
|
|||
targetFrame.size.width += (toFrame.size.width - fromFrame.size.width) * progressPercentage
|
||||
targetFrame.origin.x += (toFrame.origin.x - fromFrame.origin.x) * progressPercentage
|
||||
|
||||
selectedBar.frame = CGRectMake(targetFrame.origin.x, selectedBar.frame.origin.y, targetFrame.size.width, selectedBar.frame.size.height)
|
||||
selectedBar.frame = CGRect(x: targetFrame.origin.x, y: selectedBar.frame.origin.y, width: targetFrame.size.width, height: selectedBar.frame.size.height)
|
||||
|
||||
var targetContentOffset: CGFloat = 0.0
|
||||
if contentSize.width > frame.size.width {
|
||||
|
|
@ -106,23 +106,23 @@ public class ButtonBarView: UICollectionView {
|
|||
}
|
||||
|
||||
let animated = abs(contentOffset.x - targetContentOffset) > 30 || (fromIndex == toIndex)
|
||||
setContentOffset(CGPointMake(targetContentOffset, 0), animated: animated)
|
||||
setContentOffset(CGPoint(x: targetContentOffset, y: 0), animated: animated)
|
||||
}
|
||||
|
||||
public func updateSelectedBarPosition(animated: Bool, swipeDirection: SwipeDirection, pagerScroll: PagerScroll) -> Void {
|
||||
open func updateSelectedBarPosition(_ animated: Bool, swipeDirection: SwipeDirection, pagerScroll: PagerScroll) -> Void {
|
||||
var selectedBarFrame = selectedBar.frame
|
||||
|
||||
let selectedCellIndexPath = NSIndexPath(forItem: selectedIndex, inSection: 0)
|
||||
let attributes = layoutAttributesForItemAtIndexPath(selectedCellIndexPath)
|
||||
let selectedCellIndexPath = IndexPath(item: selectedIndex, section: 0)
|
||||
let attributes = layoutAttributesForItem(at: selectedCellIndexPath)
|
||||
let selectedCellFrame = attributes!.frame
|
||||
|
||||
updateContentOffset(animated, pagerScroll: pagerScroll, toFrame: selectedCellFrame, toIndex: selectedCellIndexPath.row)
|
||||
updateContentOffset(animated: animated, pagerScroll: pagerScroll, toFrame: selectedCellFrame, toIndex: (selectedCellIndexPath as NSIndexPath).row)
|
||||
|
||||
selectedBarFrame.size.width = selectedCellFrame.size.width
|
||||
selectedBarFrame.origin.x = selectedCellFrame.origin.x
|
||||
|
||||
if animated {
|
||||
UIView.animateWithDuration(0.3, animations: { [weak self] in
|
||||
UIView.animate(withDuration: 0.3, animations: { [weak self] in
|
||||
self?.selectedBar.frame = selectedBarFrame
|
||||
})
|
||||
}
|
||||
|
|
@ -134,9 +134,9 @@ public class ButtonBarView: UICollectionView {
|
|||
// MARK: - Helpers
|
||||
|
||||
private func updateContentOffset(animated: Bool, pagerScroll: PagerScroll, toFrame: CGRect, toIndex: Int) -> Void {
|
||||
guard pagerScroll != .No || (pagerScroll != .ScrollOnlyIfOutOfScreen && (toFrame.origin.x < contentOffset.x || toFrame.origin.x >= (contentOffset.x + frame.size.width - contentInset.left))) else { return }
|
||||
guard pagerScroll != .no || (pagerScroll != .scrollOnlyIfOutOfScreen && (toFrame.origin.x < contentOffset.x || toFrame.origin.x >= (contentOffset.x + frame.size.width - contentInset.left))) else { return }
|
||||
let targetContentOffset = contentSize.width > frame.size.width ? contentOffsetForCell(withFrame: toFrame, andIndex: toIndex) : 0
|
||||
setContentOffset(CGPointMake(targetContentOffset, 0), animated: animated)
|
||||
setContentOffset(CGPoint(x: targetContentOffset, y: 0), animated: animated)
|
||||
}
|
||||
|
||||
private func contentOffsetForCell(withFrame cellFrame: CGRect, andIndex index: Int) -> CGFloat {
|
||||
|
|
@ -144,13 +144,13 @@ public class ButtonBarView: UICollectionView {
|
|||
var alignmentOffset: CGFloat = 0.0
|
||||
|
||||
switch selectedBarAlignment {
|
||||
case .Left:
|
||||
case .left:
|
||||
alignmentOffset = sectionInset.left
|
||||
case .Right:
|
||||
case .right:
|
||||
alignmentOffset = frame.size.width - sectionInset.right - cellFrame.size.width
|
||||
case .Center:
|
||||
case .center:
|
||||
alignmentOffset = (frame.size.width - cellFrame.size.width) * 0.5
|
||||
case .Progressive:
|
||||
case .progressive:
|
||||
let cellHalfWidth = cellFrame.size.width * 0.5
|
||||
let leftAlignmentOffset = sectionInset.left + cellHalfWidth
|
||||
let rightAlignmentOffset = frame.size.width - sectionInset.right - cellHalfWidth
|
||||
|
|
|
|||
|
|
@ -24,19 +24,19 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
public class ButtonBarViewCell: UICollectionViewCell {
|
||||
open class ButtonBarViewCell: UICollectionViewCell {
|
||||
|
||||
@IBOutlet public var imageView: UIImageView!
|
||||
@IBOutlet public lazy var label: UILabel! = { [unowned self] in
|
||||
@IBOutlet open var imageView: UIImageView!
|
||||
@IBOutlet open lazy var label: UILabel! = { [unowned self] in
|
||||
let label = UILabel(frame: self.contentView.bounds)
|
||||
label.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
|
||||
label.textAlignment = .Center
|
||||
label.font = UIFont.boldSystemFontOfSize(14.0)
|
||||
label.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||
label.textAlignment = .center
|
||||
label.font = UIFont.boldSystemFont(ofSize: 14.0)
|
||||
return label
|
||||
}()
|
||||
|
||||
public override func willMoveToSuperview(newSuperview: UIView?) {
|
||||
super.willMoveToSuperview(newSuperview)
|
||||
open override func willMove(toSuperview newSuperview: UIView?) {
|
||||
super.willMove(toSuperview: newSuperview)
|
||||
|
||||
if label.superview != nil {
|
||||
contentView.addSubview(label)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public struct IndicatorInfo {
|
|||
}
|
||||
|
||||
|
||||
extension IndicatorInfo : StringLiteralConvertible {
|
||||
extension IndicatorInfo : ExpressibleByStringLiteral {
|
||||
|
||||
public init(stringLiteral value: String){
|
||||
title = value
|
||||
|
|
@ -59,4 +59,4 @@ extension IndicatorInfo : StringLiteralConvertible {
|
|||
public init(unicodeScalarLiteral value: String){
|
||||
title = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,14 +26,14 @@ import Foundation
|
|||
|
||||
public enum PagerTabStripBehaviour {
|
||||
|
||||
case Common(skipIntermediateViewControllers: Bool)
|
||||
case Progressive(skipIntermediateViewControllers: Bool, elasticIndicatorLimit: Bool)
|
||||
case common(skipIntermediateViewControllers: Bool)
|
||||
case progressive(skipIntermediateViewControllers: Bool, elasticIndicatorLimit: Bool)
|
||||
|
||||
public var skipIntermediateViewControllers: Bool {
|
||||
switch self {
|
||||
case .Common(let skipIntermediateViewControllers):
|
||||
case .common(let skipIntermediateViewControllers):
|
||||
return skipIntermediateViewControllers
|
||||
case .Progressive(let skipIntermediateViewControllers, _):
|
||||
case .progressive(let skipIntermediateViewControllers, _):
|
||||
return skipIntermediateViewControllers
|
||||
}
|
||||
}
|
||||
|
|
@ -41,18 +41,18 @@ public enum PagerTabStripBehaviour {
|
|||
|
||||
public var isProgressiveIndicator: Bool {
|
||||
switch self {
|
||||
case .Common(_):
|
||||
case .common(_):
|
||||
return false
|
||||
case .Progressive(_, _):
|
||||
case .progressive(_, _):
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public var isElasticIndicatorLimit: Bool {
|
||||
switch self {
|
||||
case .Common(_):
|
||||
case .common(_):
|
||||
return false
|
||||
case .Progressive(_, let elasticIndicatorLimit):
|
||||
case .progressive(_, let elasticIndicatorLimit):
|
||||
return elasticIndicatorLimit
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,6 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
public enum PagerTabStripError: ErrorType {
|
||||
case ViewControllerNotContainedInPagerTabStrip
|
||||
}
|
||||
public enum PagerTabStripError: Error {
|
||||
case viewControllerNotContainedInPagerTabStrip
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,66 +30,66 @@ import Foundation
|
|||
|
||||
public protocol IndicatorInfoProvider {
|
||||
|
||||
func indicatorInfoForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo
|
||||
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo
|
||||
}
|
||||
|
||||
public protocol PagerTabStripDelegate: class {
|
||||
|
||||
func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int)
|
||||
func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int)
|
||||
}
|
||||
|
||||
public protocol PagerTabStripIsProgressiveDelegate : PagerTabStripDelegate {
|
||||
|
||||
func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool)
|
||||
func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool)
|
||||
}
|
||||
|
||||
public protocol PagerTabStripDataSource: class {
|
||||
|
||||
func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController]
|
||||
func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController]
|
||||
}
|
||||
|
||||
|
||||
//MARK: PagerTabStripViewController
|
||||
|
||||
public class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
|
||||
open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
|
||||
|
||||
@IBOutlet lazy public var containerView: UIScrollView! = { [unowned self] in
|
||||
let containerView = UIScrollView(frame: CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)))
|
||||
containerView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
|
||||
@IBOutlet lazy open var containerView: UIScrollView! = { [unowned self] in
|
||||
let containerView = UIScrollView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height))
|
||||
containerView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||
return containerView
|
||||
}()
|
||||
|
||||
public weak var delegate: PagerTabStripDelegate?
|
||||
public weak var datasource: PagerTabStripDataSource?
|
||||
open weak var delegate: PagerTabStripDelegate?
|
||||
open weak var datasource: PagerTabStripDataSource?
|
||||
|
||||
public var pagerBehaviour = PagerTabStripBehaviour.Progressive(skipIntermediateViewControllers: true, elasticIndicatorLimit: true)
|
||||
open var pagerBehaviour = PagerTabStripBehaviour.progressive(skipIntermediateViewControllers: true, elasticIndicatorLimit: true)
|
||||
|
||||
public private(set) var viewControllers = [UIViewController]()
|
||||
public private(set) var currentIndex = 0
|
||||
open private(set) var viewControllers = [UIViewController]()
|
||||
open private(set) var currentIndex = 0
|
||||
|
||||
public var pageWidth: CGFloat {
|
||||
return CGRectGetWidth(containerView.bounds)
|
||||
open var pageWidth: CGFloat {
|
||||
return containerView.bounds.width
|
||||
}
|
||||
|
||||
public var scrollPercentage: CGFloat {
|
||||
if swipeDirection != .Right {
|
||||
open var scrollPercentage: CGFloat {
|
||||
if swipeDirection != .right {
|
||||
let module = fmod(containerView.contentOffset.x, pageWidth)
|
||||
return module == 0.0 ? 1.0 : module / pageWidth
|
||||
}
|
||||
return 1 - fmod(containerView.contentOffset.x >= 0 ? containerView.contentOffset.x : pageWidth + containerView.contentOffset.x, pageWidth) / pageWidth
|
||||
}
|
||||
|
||||
public var swipeDirection: SwipeDirection {
|
||||
open var swipeDirection: SwipeDirection {
|
||||
if containerView.contentOffset.x > lastContentOffset {
|
||||
return .Left
|
||||
return .left
|
||||
}
|
||||
else if containerView.contentOffset.x < lastContentOffset {
|
||||
return .Right
|
||||
return .right
|
||||
}
|
||||
return .None
|
||||
return .none
|
||||
}
|
||||
|
||||
override public func viewDidLoad() {
|
||||
override open func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
if containerView.superview == nil {
|
||||
view.addSubview(containerView)
|
||||
|
|
@ -101,29 +101,29 @@ public class PagerTabStripViewController: UIViewController, UIScrollViewDelegate
|
|||
containerView.delegate = self
|
||||
containerView.showsVerticalScrollIndicator = false
|
||||
containerView.showsHorizontalScrollIndicator = false
|
||||
containerView.pagingEnabled = true
|
||||
containerView.isPagingEnabled = true
|
||||
reloadViewControllers()
|
||||
}
|
||||
|
||||
public override func viewWillAppear(animated: Bool) {
|
||||
open override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
isViewAppearing = true
|
||||
}
|
||||
|
||||
override public func viewDidAppear(animated: Bool) {
|
||||
override open func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
lastSize = containerView.bounds.size
|
||||
updateIfNeeded()
|
||||
isViewAppearing = false
|
||||
}
|
||||
|
||||
override public func viewDidLayoutSubviews(){
|
||||
override open func viewDidLayoutSubviews(){
|
||||
super.viewDidLayoutSubviews()
|
||||
updateIfNeeded()
|
||||
}
|
||||
|
||||
public func moveToViewControllerAtIndex(index: Int, animated: Bool = true) {
|
||||
guard isViewLoaded() && view.window != nil else {
|
||||
open func moveToViewController(at index: Int, animated: Bool = true) {
|
||||
guard isViewLoaded && view.window != nil else {
|
||||
currentIndex = index
|
||||
return
|
||||
}
|
||||
|
|
@ -135,64 +135,64 @@ public class PagerTabStripViewController: UIViewController, UIScrollViewDelegate
|
|||
tmpViewControllers[currentIndex] = fromChildVC
|
||||
tmpViewControllers[fromIndex] = currentChildVC
|
||||
pagerTabStripChildViewControllersForScrolling = tmpViewControllers
|
||||
containerView.setContentOffset(CGPointMake(pageOffsetForChildIndex(index: fromIndex), 0), animated: false)
|
||||
(navigationController?.view ?? view).userInteractionEnabled = false
|
||||
containerView.setContentOffset(CGPointMake(pageOffsetForChildIndex(index: index), 0), animated: true)
|
||||
containerView.setContentOffset(CGPoint(x: pageOffsetForChild(at: fromIndex), y: 0), animated: false)
|
||||
(navigationController?.view ?? view).isUserInteractionEnabled = false
|
||||
containerView.setContentOffset(CGPoint(x: pageOffsetForChild(at: index), y: 0), animated: true)
|
||||
}
|
||||
else {
|
||||
(navigationController?.view ?? view).userInteractionEnabled = false
|
||||
containerView.setContentOffset(CGPointMake(pageOffsetForChildIndex(index: index), 0), animated: animated)
|
||||
(navigationController?.view ?? view).isUserInteractionEnabled = false
|
||||
containerView.setContentOffset(CGPoint(x: pageOffsetForChild(at: index), y: 0), animated: animated)
|
||||
}
|
||||
}
|
||||
|
||||
public func moveToViewController(viewController: UIViewController, animated: Bool = true) {
|
||||
moveToViewControllerAtIndex(viewControllers.indexOf(viewController)!, animated: animated)
|
||||
open func moveTo(viewController: UIViewController, animated: Bool = true) {
|
||||
moveToViewController(at: viewControllers.index(of: viewController)!, animated: animated)
|
||||
}
|
||||
|
||||
//MARK: - PagerTabStripDataSource
|
||||
|
||||
public func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
open func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
|
||||
assertionFailure("Sub-class must implement the PagerTabStripDataSource viewControllersForPagerTabStrip: method")
|
||||
return []
|
||||
}
|
||||
|
||||
//MARK: - Helpers
|
||||
|
||||
public func updateIfNeeded() {
|
||||
if isViewLoaded() && !CGSizeEqualToSize(lastSize, containerView.bounds.size){
|
||||
open func updateIfNeeded() {
|
||||
if isViewLoaded && !lastSize.equalTo(containerView.bounds.size){
|
||||
updateContent()
|
||||
}
|
||||
}
|
||||
|
||||
public func canMoveToIndex(index index: Int) -> Bool {
|
||||
open func canMoveTo(index: Int) -> Bool {
|
||||
return currentIndex != index && viewControllers.count > index
|
||||
}
|
||||
|
||||
public func pageOffsetForChildIndex(index index: Int) -> CGFloat {
|
||||
return CGFloat(index) * CGRectGetWidth(containerView.bounds)
|
||||
open func pageOffsetForChild(at index: Int) -> CGFloat {
|
||||
return CGFloat(index) * containerView.bounds.width
|
||||
}
|
||||
|
||||
public func offsetForChildIndex(index: Int) -> CGFloat{
|
||||
return (CGFloat(index) * CGRectGetWidth(containerView.bounds)) + ((CGRectGetWidth(containerView.bounds) - CGRectGetWidth(view.bounds)) * 0.5)
|
||||
open func offsetForChild(at index: Int) -> CGFloat{
|
||||
return (CGFloat(index) * containerView.bounds.width) + ((containerView.bounds.width - view.bounds.width) * 0.5)
|
||||
}
|
||||
|
||||
public func offsetForChildViewController(viewController: UIViewController) throws -> CGFloat{
|
||||
guard let index = viewControllers.indexOf(viewController) else {
|
||||
throw PagerTabStripError.ViewControllerNotContainedInPagerTabStrip
|
||||
open func offsetForChild(viewController: UIViewController) throws -> CGFloat{
|
||||
guard let index = viewControllers.index(of: viewController) else {
|
||||
throw PagerTabStripError.viewControllerNotContainedInPagerTabStrip
|
||||
}
|
||||
return offsetForChildIndex(index)
|
||||
return offsetForChild(at: index)
|
||||
}
|
||||
|
||||
public func pageForContentOffset(contentOffset: CGFloat) -> Int {
|
||||
let result = virtualPageForContentOffset(contentOffset)
|
||||
return pageForVirtualPage(result)
|
||||
open func pageFor(contentOffset: CGFloat) -> Int {
|
||||
let result = virtualPageFor(contentOffset: contentOffset)
|
||||
return pageFor(virtualPage: result)
|
||||
}
|
||||
|
||||
public func virtualPageForContentOffset(contentOffset: CGFloat) -> Int {
|
||||
open func virtualPageFor(contentOffset: CGFloat) -> Int {
|
||||
return Int((contentOffset + 1.5 * pageWidth) / pageWidth) - 1
|
||||
}
|
||||
|
||||
public func pageForVirtualPage(virtualPage: Int) -> Int{
|
||||
open func pageFor(virtualPage: Int) -> Int{
|
||||
if virtualPage < 0 {
|
||||
return 0
|
||||
}
|
||||
|
|
@ -202,36 +202,36 @@ public class PagerTabStripViewController: UIViewController, UIScrollViewDelegate
|
|||
return virtualPage
|
||||
}
|
||||
|
||||
public func updateContent() {
|
||||
open func updateContent() {
|
||||
if lastSize.width != containerView.bounds.size.width {
|
||||
lastSize = containerView.bounds.size
|
||||
containerView.contentOffset = CGPointMake(pageOffsetForChildIndex(index: currentIndex), 0)
|
||||
containerView.contentOffset = CGPoint(x: pageOffsetForChild(at: currentIndex), y: 0)
|
||||
}
|
||||
lastSize = containerView.bounds.size
|
||||
|
||||
let pagerViewControllers = pagerTabStripChildViewControllersForScrolling ?? viewControllers
|
||||
containerView.contentSize = CGSizeMake(CGRectGetWidth(containerView.bounds) * CGFloat(pagerViewControllers.count), containerView.contentSize.height)
|
||||
containerView.contentSize = CGSize(width: containerView.bounds.width * CGFloat(pagerViewControllers.count), height: containerView.contentSize.height)
|
||||
|
||||
for (index, childController) in pagerViewControllers.enumerate() {
|
||||
let pageOffsetForChild = pageOffsetForChildIndex(index: index)
|
||||
if fabs(containerView.contentOffset.x - pageOffsetForChild) < CGRectGetWidth(containerView.bounds) {
|
||||
if let _ = childController.parentViewController {
|
||||
childController.view.frame = CGRectMake(offsetForChildIndex(index), 0, CGRectGetWidth(view.bounds), CGRectGetHeight(containerView.bounds))
|
||||
childController.view.autoresizingMask = [.FlexibleHeight, .FlexibleWidth]
|
||||
for (index, childController) in pagerViewControllers.enumerated() {
|
||||
let pageOffsetForChild = self.pageOffsetForChild(at: index)
|
||||
if fabs(containerView.contentOffset.x - pageOffsetForChild) < containerView.bounds.width {
|
||||
if let _ = childController.parent {
|
||||
childController.view.frame = CGRect(x: offsetForChild(at: index), y: 0, width: view.bounds.width, height: containerView.bounds.height)
|
||||
childController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
|
||||
}
|
||||
else {
|
||||
addChildViewController(childController)
|
||||
childController.beginAppearanceTransition(true, animated: false)
|
||||
childController.view.frame = CGRectMake(offsetForChildIndex(index), 0, CGRectGetWidth(view.bounds), CGRectGetHeight(containerView.bounds))
|
||||
childController.view.autoresizingMask = [.FlexibleHeight, .FlexibleWidth]
|
||||
childController.view.frame = CGRect(x: offsetForChild(at: index), y: 0, width: view.bounds.width, height: containerView.bounds.height)
|
||||
childController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
|
||||
containerView.addSubview(childController.view)
|
||||
childController.didMoveToParentViewController(self)
|
||||
childController.didMove(toParentViewController: self)
|
||||
childController.endAppearanceTransition()
|
||||
}
|
||||
}
|
||||
else {
|
||||
if let _ = childController.parentViewController {
|
||||
childController.willMoveToParentViewController(nil)
|
||||
if let _ = childController.parent {
|
||||
childController.willMove(toParentViewController: nil)
|
||||
childController.beginAppearanceTransition(false, animated: false)
|
||||
childController.view.removeFromSuperview()
|
||||
childController.removeFromParentViewController()
|
||||
|
|
@ -241,69 +241,69 @@ public class PagerTabStripViewController: UIViewController, UIScrollViewDelegate
|
|||
}
|
||||
|
||||
let oldCurrentIndex = currentIndex
|
||||
let virtualPage = virtualPageForContentOffset(containerView.contentOffset.x)
|
||||
let newCurrentIndex = pageForVirtualPage(virtualPage)
|
||||
let virtualPage = virtualPageFor(contentOffset: containerView.contentOffset.x)
|
||||
let newCurrentIndex = pageFor(virtualPage: virtualPage)
|
||||
currentIndex = newCurrentIndex
|
||||
let changeCurrentIndex = newCurrentIndex != oldCurrentIndex
|
||||
|
||||
if let progressiveDeledate = self as? PagerTabStripIsProgressiveDelegate where pagerBehaviour.isProgressiveIndicator {
|
||||
if let progressiveDeledate = self as? PagerTabStripIsProgressiveDelegate, pagerBehaviour.isProgressiveIndicator {
|
||||
|
||||
let (fromIndex, toIndex, scrollPercentage) = progressiveIndicatorData(virtualPage)
|
||||
progressiveDeledate.pagerTabStripViewController(self, updateIndicatorFromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: scrollPercentage, indexWasChanged: changeCurrentIndex)
|
||||
progressiveDeledate.updateIndicator(for: self, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: scrollPercentage, indexWasChanged: changeCurrentIndex)
|
||||
}
|
||||
else{
|
||||
delegate?.pagerTabStripViewController(self, updateIndicatorFromIndex: min(oldCurrentIndex, pagerViewControllers.count - 1), toIndex: newCurrentIndex)
|
||||
delegate?.updateIndicator(for: self, fromIndex: min(oldCurrentIndex, pagerViewControllers.count - 1), toIndex: newCurrentIndex)
|
||||
}
|
||||
}
|
||||
|
||||
public func reloadPagerTabStripView() {
|
||||
guard isViewLoaded() else { return }
|
||||
open func reloadPagerTabStripView() {
|
||||
guard isViewLoaded else { return }
|
||||
for childController in viewControllers {
|
||||
if let _ = childController.parentViewController {
|
||||
if let _ = childController.parent {
|
||||
childController.view.removeFromSuperview()
|
||||
childController.willMoveToParentViewController(nil)
|
||||
childController.willMove(toParentViewController: nil)
|
||||
childController.removeFromParentViewController()
|
||||
}
|
||||
}
|
||||
reloadViewControllers()
|
||||
containerView.contentSize = CGSizeMake(CGRectGetWidth(containerView.bounds) * CGFloat(viewControllers.count), containerView.contentSize.height)
|
||||
containerView.contentSize = CGSize(width: containerView.bounds.width * CGFloat(viewControllers.count), height: containerView.contentSize.height)
|
||||
if currentIndex >= viewControllers.count {
|
||||
currentIndex = viewControllers.count - 1
|
||||
}
|
||||
containerView.contentOffset = CGPointMake(pageOffsetForChildIndex(index: currentIndex), 0)
|
||||
containerView.contentOffset = CGPoint(x: pageOffsetForChild(at: currentIndex), y: 0)
|
||||
updateContent()
|
||||
}
|
||||
|
||||
//MARK: - UIScrollDelegate
|
||||
|
||||
public func scrollViewDidScroll(scrollView: UIScrollView) {
|
||||
open func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||
if containerView == scrollView {
|
||||
updateContent()
|
||||
}
|
||||
}
|
||||
|
||||
public func scrollViewWillBeginDragging(scrollView: UIScrollView) {
|
||||
open func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
|
||||
if containerView == scrollView {
|
||||
lastPageNumber = pageForContentOffset(scrollView.contentOffset.x)
|
||||
lastPageNumber = pageFor(contentOffset: scrollView.contentOffset.x)
|
||||
lastContentOffset = scrollView.contentOffset.x
|
||||
}
|
||||
}
|
||||
|
||||
public func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
|
||||
open func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
|
||||
if containerView == scrollView {
|
||||
pagerTabStripChildViewControllersForScrolling = nil
|
||||
(navigationController?.view ?? view).userInteractionEnabled = true
|
||||
(navigationController?.view ?? view).isUserInteractionEnabled = true
|
||||
updateContent()
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Orientation
|
||||
|
||||
public override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
|
||||
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
|
||||
open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
||||
super.viewWillTransition(to: size, with: coordinator)
|
||||
isViewRotating = true
|
||||
pageBeforeRotate = currentIndex
|
||||
coordinator.animateAlongsideTransition(nil) { [weak self] _ in
|
||||
coordinator.animate(alongsideTransition: nil) { [weak self] _ in
|
||||
guard let me = self else { return }
|
||||
me.isViewRotating = false
|
||||
me.currentIndex = me.pageBeforeRotate
|
||||
|
|
@ -314,13 +314,13 @@ public class PagerTabStripViewController: UIViewController, UIScrollViewDelegate
|
|||
|
||||
//MARK: Private
|
||||
|
||||
private func progressiveIndicatorData(virtualPage: Int) -> (Int, Int, CGFloat) {
|
||||
private func progressiveIndicatorData(_ virtualPage: Int) -> (Int, Int, CGFloat) {
|
||||
let count = viewControllers.count
|
||||
var fromIndex = currentIndex
|
||||
var toIndex = currentIndex
|
||||
let direction = swipeDirection
|
||||
|
||||
if direction == .Left {
|
||||
if direction == .left {
|
||||
if virtualPage > count - 1 {
|
||||
fromIndex = count - 1
|
||||
toIndex = count
|
||||
|
|
@ -334,7 +334,7 @@ public class PagerTabStripViewController: UIViewController, UIScrollViewDelegate
|
|||
}
|
||||
}
|
||||
}
|
||||
else if direction == .Right {
|
||||
else if direction == .right {
|
||||
if virtualPage < 0 {
|
||||
fromIndex = 0
|
||||
toIndex = -1
|
||||
|
|
@ -356,7 +356,7 @@ public class PagerTabStripViewController: UIViewController, UIScrollViewDelegate
|
|||
guard let dataSource = datasource else {
|
||||
fatalError("dataSource must not be nil")
|
||||
}
|
||||
viewControllers = dataSource.viewControllersForPagerTabStrip(self)
|
||||
viewControllers = dataSource.viewControllers(for: self)
|
||||
// viewControllers
|
||||
guard viewControllers.count != 0 else {
|
||||
fatalError("viewControllersForPagerTabStrip should provide at least one child view controller")
|
||||
|
|
@ -369,7 +369,7 @@ public class PagerTabStripViewController: UIViewController, UIScrollViewDelegate
|
|||
private var lastPageNumber = 0
|
||||
private var lastContentOffset: CGFloat = 0.0
|
||||
private var pageBeforeRotate = 0
|
||||
private var lastSize = CGSizeMake(0, 0)
|
||||
private var lastSize = CGSize(width: 0, height: 0)
|
||||
internal var isViewRotating = false
|
||||
internal var isViewAppearing = false
|
||||
|
||||
|
|
|
|||
|
|
@ -34,69 +34,69 @@ public struct SegmentedPagerTabStripSettings {
|
|||
}
|
||||
|
||||
|
||||
public class SegmentedPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripDelegate {
|
||||
open class SegmentedPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripDelegate {
|
||||
|
||||
@IBOutlet lazy public var segmentedControl: UISegmentedControl! = UISegmentedControl()
|
||||
@IBOutlet lazy open var segmentedControl: UISegmentedControl! = UISegmentedControl()
|
||||
|
||||
public var settings = SegmentedPagerTabStripSettings()
|
||||
open var settings = SegmentedPagerTabStripSettings()
|
||||
|
||||
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
|
||||
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
|
||||
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
||||
pagerBehaviour = PagerTabStripBehaviour.Common(skipIntermediateViewControllers: true)
|
||||
pagerBehaviour = PagerTabStripBehaviour.common(skipIntermediateViewControllers: true)
|
||||
delegate = self
|
||||
datasource = self
|
||||
}
|
||||
|
||||
required public init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
pagerBehaviour = PagerTabStripBehaviour.Common(skipIntermediateViewControllers: true)
|
||||
pagerBehaviour = PagerTabStripBehaviour.common(skipIntermediateViewControllers: true)
|
||||
delegate = self
|
||||
datasource = self
|
||||
}
|
||||
|
||||
private(set) var shouldUpdateSegmentedControl = true
|
||||
|
||||
public override func viewDidLoad() {
|
||||
open override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
if segmentedControl.superview == nil {
|
||||
navigationItem.titleView = segmentedControl
|
||||
}
|
||||
segmentedControl.tintColor = settings.style.segmentedControlColor ?? segmentedControl.tintColor
|
||||
segmentedControl.addTarget(self, action: #selector(SegmentedPagerTabStripViewController.segmentedControlChanged(_:)), forControlEvents: .ValueChanged)
|
||||
segmentedControl.addTarget(self, action: #selector(SegmentedPagerTabStripViewController.segmentedControlChanged(_:)), for: .valueChanged)
|
||||
reloadSegmentedControl()
|
||||
}
|
||||
|
||||
public override func reloadPagerTabStripView() {
|
||||
open override func reloadPagerTabStripView() {
|
||||
super.reloadPagerTabStripView()
|
||||
if isViewLoaded() {
|
||||
if isViewLoaded {
|
||||
reloadSegmentedControl()
|
||||
}
|
||||
}
|
||||
|
||||
func reloadSegmentedControl() {
|
||||
segmentedControl.removeAllSegments()
|
||||
for (index, item) in viewControllers.enumerate(){
|
||||
for (index, item) in viewControllers.enumerated(){
|
||||
let child = item as! IndicatorInfoProvider
|
||||
if let image = child.indicatorInfoForPagerTabStrip(self).image {
|
||||
segmentedControl.insertSegmentWithImage(image, atIndex: index, animated: false)
|
||||
if let image = child.indicatorInfo(for: self).image {
|
||||
segmentedControl.insertSegment(with: image, at: index, animated: false)
|
||||
}
|
||||
else {
|
||||
segmentedControl.insertSegmentWithTitle(child.indicatorInfoForPagerTabStrip(self).title, atIndex: index, animated: false)
|
||||
segmentedControl.insertSegment(withTitle: child.indicatorInfo(for: self).title, at: index, animated: false)
|
||||
}
|
||||
}
|
||||
segmentedControl.selectedSegmentIndex = currentIndex
|
||||
}
|
||||
|
||||
func segmentedControlChanged(sender: UISegmentedControl) {
|
||||
func segmentedControlChanged(_ sender: UISegmentedControl) {
|
||||
let index = sender.selectedSegmentIndex
|
||||
pagerTabStripViewController(self, updateIndicatorFromIndex: currentIndex, toIndex: index)
|
||||
updateIndicator(for: self, fromIndex: currentIndex, toIndex: index)
|
||||
shouldUpdateSegmentedControl = false
|
||||
moveToViewControllerAtIndex(index)
|
||||
moveToViewController(at: index)
|
||||
}
|
||||
|
||||
// MARK: - PagerTabStripDelegate
|
||||
|
||||
public func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int) {
|
||||
|
||||
open func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int) {
|
||||
if shouldUpdateSegmentedControl {
|
||||
segmentedControl.selectedSegmentIndex = toIndex
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ public class SegmentedPagerTabStripViewController: PagerTabStripViewController,
|
|||
|
||||
// MARK: - UIScrollViewDelegate
|
||||
|
||||
public override func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
|
||||
open override func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
|
||||
super.scrollViewDidEndScrollingAnimation(scrollView)
|
||||
shouldUpdateSegmentedControl = true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
import Foundation
|
||||
|
||||
public enum SwipeDirection {
|
||||
case Left
|
||||
case Right
|
||||
case None
|
||||
}
|
||||
case left
|
||||
case right
|
||||
case none
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,34 +28,34 @@ public struct TwitterPagerTabStripSettings {
|
|||
|
||||
public struct Style {
|
||||
public var dotColor = UIColor(white: 1, alpha: 0.4)
|
||||
public var selectedDotColor = UIColor.whiteColor()
|
||||
public var portraitTitleFont = UIFont.systemFontOfSize(18)
|
||||
public var landscapeTitleFont = UIFont.systemFontOfSize(15)
|
||||
public var titleColor = UIColor.whiteColor()
|
||||
public var selectedDotColor = UIColor.white
|
||||
public var portraitTitleFont = UIFont.systemFont(ofSize: 18)
|
||||
public var landscapeTitleFont = UIFont.systemFont(ofSize: 15)
|
||||
public var titleColor = UIColor.white
|
||||
}
|
||||
|
||||
public var style = Style()
|
||||
}
|
||||
|
||||
public class TwitterPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate {
|
||||
open class TwitterPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate {
|
||||
|
||||
public var settings = TwitterPagerTabStripSettings()
|
||||
open var settings = TwitterPagerTabStripSettings()
|
||||
|
||||
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
|
||||
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
|
||||
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
||||
pagerBehaviour = .Progressive(skipIntermediateViewControllers: true, elasticIndicatorLimit: true)
|
||||
pagerBehaviour = .progressive(skipIntermediateViewControllers: true, elasticIndicatorLimit: true)
|
||||
delegate = self
|
||||
datasource = self
|
||||
}
|
||||
|
||||
required public init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
pagerBehaviour = .Progressive(skipIntermediateViewControllers: true, elasticIndicatorLimit: true)
|
||||
pagerBehaviour = .progressive(skipIntermediateViewControllers: true, elasticIndicatorLimit: true)
|
||||
delegate = self
|
||||
datasource = self
|
||||
}
|
||||
|
||||
public override func viewDidLoad() {
|
||||
open override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
if titleView.superview == nil {
|
||||
|
|
@ -63,33 +63,29 @@ public class TwitterPagerTabStripViewController: PagerTabStripViewController, Pa
|
|||
}
|
||||
|
||||
// keep watching the frame of titleView
|
||||
titleView.addObserver(self, forKeyPath: "frame", options: [.New, .Old], context: nil)
|
||||
titleView.addObserver(self, forKeyPath: "frame", options: [.new, .old], context: nil)
|
||||
|
||||
guard let navigationController = navigationController else {
|
||||
fatalError("TwitterPagerTabStripViewController should be embedded in a UINavigationController")
|
||||
}
|
||||
titleView.frame = CGRectMake(0, 0, CGRectGetWidth(navigationController.navigationBar.frame), CGRectGetHeight(navigationController.navigationBar.frame))
|
||||
titleView.frame = CGRect(x: 0, y: 0, width: navigationController.navigationBar.frame.width, height: navigationController.navigationBar.frame.height)
|
||||
titleView.addSubview(titleScrollView)
|
||||
titleView.addSubview(pageControl)
|
||||
reloadNavigationViewItems()
|
||||
}
|
||||
|
||||
public override func reloadPagerTabStripView() {
|
||||
open override func reloadPagerTabStripView() {
|
||||
super.reloadPagerTabStripView()
|
||||
guard isViewLoaded() else { return }
|
||||
guard isViewLoaded else { return }
|
||||
|
||||
reloadNavigationViewItems()
|
||||
setNavigationViewItemsPosition(updateAlpha: true)
|
||||
}
|
||||
|
||||
// MARK: - PagerTabStripDelegate
|
||||
|
||||
public func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int) {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
public func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
|
||||
|
||||
|
||||
open func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
|
||||
|
||||
// move indicator scroll view
|
||||
let distance = distanceValue
|
||||
var xOffset: CGFloat = 0
|
||||
|
|
@ -102,22 +98,27 @@ public class TwitterPagerTabStripViewController: PagerTabStripViewController, Pa
|
|||
else {
|
||||
xOffset = distance * CGFloat(fromIndex)
|
||||
}
|
||||
|
||||
titleScrollView.contentOffset = CGPointMake(xOffset, 0)
|
||||
|
||||
|
||||
titleScrollView.contentOffset = CGPoint(x: xOffset, y: 0)
|
||||
|
||||
// update alpha of titles
|
||||
setAlphaWithOffset(xOffset, andDistance: distance)
|
||||
|
||||
setAlphaWith(offset: xOffset, andDistance: distance)
|
||||
|
||||
// update page control page
|
||||
pageControl.currentPage = currentIndex
|
||||
}
|
||||
|
||||
open func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int) {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
public override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
|
||||
guard object === titleView && keyPath == "frame" && change?[NSKeyValueChangeKindKey] as? UInt == NSKeyValueChange.Setting.rawValue else { return }
|
||||
let oldRect = change![NSKeyValueChangeOldKey]!.CGRectValue
|
||||
let newRect = change![NSKeyValueChangeOldKey]!.CGRectValue
|
||||
if CGRectEqualToRect(oldRect, newRect) {
|
||||
titleScrollView.frame = CGRectMake(0, 0, CGRectGetWidth(titleView.frame), CGRectGetHeight(titleScrollView.frame))
|
||||
open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
||||
guard object as AnyObject === titleView && keyPath == "frame" && change?[NSKeyValueChangeKey.kindKey] as? UInt == NSKeyValueChange.setting.rawValue else { return }
|
||||
|
||||
let oldRect = (change![NSKeyValueChangeKey.oldKey]! as AnyObject).cgRectValue
|
||||
let newRect = (change![NSKeyValueChangeKey.oldKey]! as AnyObject).cgRectValue
|
||||
if (oldRect?.equalTo(newRect!))! {
|
||||
titleScrollView.frame = CGRect(x: 0, y: 0, width: titleView.frame.width, height: titleScrollView.frame.height)
|
||||
setNavigationViewItemsPosition(updateAlpha: true)
|
||||
}
|
||||
}
|
||||
|
|
@ -126,7 +127,7 @@ public class TwitterPagerTabStripViewController: PagerTabStripViewController, Pa
|
|||
titleView.removeObserver(self, forKeyPath: "frame")
|
||||
}
|
||||
|
||||
public override func viewDidLayoutSubviews() {
|
||||
open override func viewDidLayoutSubviews() {
|
||||
super.viewDidLayoutSubviews()
|
||||
setNavigationViewItemsPosition(updateAlpha: false)
|
||||
}
|
||||
|
|
@ -135,20 +136,20 @@ public class TwitterPagerTabStripViewController: PagerTabStripViewController, Pa
|
|||
|
||||
private lazy var titleView: UIView = {
|
||||
let navigationView = UIView()
|
||||
navigationView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
|
||||
navigationView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||
return navigationView
|
||||
}()
|
||||
|
||||
private lazy var titleScrollView: UIScrollView = { [unowned self] in
|
||||
let titleScrollView = UIScrollView(frame: CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 44))
|
||||
titleScrollView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
|
||||
let titleScrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 44))
|
||||
titleScrollView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||
titleScrollView.bounces = true
|
||||
titleScrollView.scrollsToTop = false
|
||||
titleScrollView.delegate = self
|
||||
titleScrollView.showsVerticalScrollIndicator = false
|
||||
titleScrollView.showsHorizontalScrollIndicator = false
|
||||
titleScrollView.pagingEnabled = true
|
||||
titleScrollView.userInteractionEnabled = false
|
||||
titleScrollView.isPagingEnabled = true
|
||||
titleScrollView.isUserInteractionEnabled = false
|
||||
titleScrollView.alwaysBounceHorizontal = true
|
||||
titleScrollView.alwaysBounceVertical = false
|
||||
return titleScrollView
|
||||
|
|
@ -156,12 +157,12 @@ public class TwitterPagerTabStripViewController: PagerTabStripViewController, Pa
|
|||
|
||||
private lazy var pageControl: FXPageControl = { [unowned self] in
|
||||
let pageControl = FXPageControl()
|
||||
pageControl.backgroundColor = .clearColor()
|
||||
pageControl.backgroundColor = .clear
|
||||
pageControl.dotSize = 3.8
|
||||
pageControl.dotSpacing = 4.0
|
||||
pageControl.dotColor = self.settings.style.dotColor
|
||||
pageControl.selectedDotColor = self.settings.style.selectedDotColor
|
||||
pageControl.userInteractionEnabled = false
|
||||
pageControl.isUserInteractionEnabled = false
|
||||
return pageControl
|
||||
}()
|
||||
|
||||
|
|
@ -171,13 +172,13 @@ public class TwitterPagerTabStripViewController: PagerTabStripViewController, Pa
|
|||
// remove all child view controller header labels
|
||||
childTitleLabels.forEach { $0.removeFromSuperview() }
|
||||
childTitleLabels.removeAll()
|
||||
for (index, item) in viewControllers.enumerate() {
|
||||
for (index, item) in viewControllers.enumerated() {
|
||||
let child = item as! IndicatorInfoProvider
|
||||
let indicatorInfo = child.indicatorInfoForPagerTabStrip(self)
|
||||
let indicatorInfo = child.indicatorInfo(for: self)
|
||||
let navTitleLabel : UILabel = {
|
||||
let label = UILabel()
|
||||
label.text = indicatorInfo.title
|
||||
label.font = UIApplication.sharedApplication().statusBarOrientation.isPortrait ? settings.style.portraitTitleFont : settings.style.landscapeTitleFont
|
||||
label.font = UIApplication.shared.statusBarOrientation.isPortrait ? settings.style.portraitTitleFont : settings.style.landscapeTitleFont
|
||||
label.textColor = settings.style.titleColor
|
||||
label.alpha = 0
|
||||
return label
|
||||
|
|
@ -189,34 +190,34 @@ public class TwitterPagerTabStripViewController: PagerTabStripViewController, Pa
|
|||
}
|
||||
}
|
||||
|
||||
private func setNavigationViewItemsPosition(updateAlpha updateAlpha: Bool) {
|
||||
private func setNavigationViewItemsPosition(updateAlpha: Bool) {
|
||||
let distance = distanceValue
|
||||
let isPortrait = UIApplication.sharedApplication().statusBarOrientation.isPortrait
|
||||
let isPortrait = UIApplication.shared.statusBarOrientation.isPortrait
|
||||
let navBarHeight: CGFloat = navigationController!.navigationBar.frame.size.height
|
||||
for (index, label) in childTitleLabels.enumerate() {
|
||||
for (index, label) in childTitleLabels.enumerated() {
|
||||
if updateAlpha {
|
||||
label.alpha = currentIndex == index ? 1 : 0
|
||||
}
|
||||
label.font = isPortrait ? settings.style.portraitTitleFont : settings.style.landscapeTitleFont
|
||||
let viewSize = label.intrinsicContentSize()
|
||||
let viewSize = label.intrinsicContentSize
|
||||
let originX = distance - viewSize.width/2 + CGFloat(index) * distance
|
||||
let originY = (CGFloat(navBarHeight) - viewSize.height) / 2
|
||||
label.frame = CGRectMake(originX, originY - 2, viewSize.width, viewSize.height)
|
||||
label.frame = CGRect(x: originX, y: originY - 2, width: viewSize.width, height: viewSize.height)
|
||||
label.tag = index
|
||||
}
|
||||
|
||||
let xOffset = distance * CGFloat(currentIndex)
|
||||
titleScrollView.contentOffset = CGPointMake(xOffset, 0)
|
||||
titleScrollView.contentOffset = CGPoint(x: xOffset, y: 0)
|
||||
|
||||
pageControl.numberOfPages = childTitleLabels.count
|
||||
pageControl.currentPage = currentIndex
|
||||
let viewSize = pageControl.sizeForNumberOfPages(childTitleLabels.count)
|
||||
let viewSize = pageControl.sizeForNumber(ofPages: childTitleLabels.count)
|
||||
let originX = distance - viewSize.width / 2
|
||||
pageControl.frame = CGRectMake(originX, navBarHeight - 10, viewSize.width, viewSize.height)
|
||||
pageControl.frame = CGRect(x: originX, y: navBarHeight - 10, width: viewSize.width, height: viewSize.height)
|
||||
}
|
||||
|
||||
private func setAlphaWithOffset(offset: CGFloat, andDistance distance: CGFloat) {
|
||||
for (index, label) in childTitleLabels.enumerate() {
|
||||
private func setAlphaWith(offset: CGFloat, andDistance distance: CGFloat) {
|
||||
for (index, label) in childTitleLabels.enumerated() {
|
||||
label.alpha = {
|
||||
if offset < distance * CGFloat(index) {
|
||||
return (offset - distance * CGFloat(index - 1)) / distance
|
||||
|
|
@ -229,7 +230,7 @@ public class TwitterPagerTabStripViewController: PagerTabStripViewController, Pa
|
|||
}
|
||||
|
||||
private var distanceValue: CGFloat {
|
||||
let middle = navigationController!.navigationBar.convertPoint(navigationController!.navigationBar.center, toView: titleView)
|
||||
let middle = navigationController!.navigationBar.convert(navigationController!.navigationBar.center, to: titleView)
|
||||
return middle.x
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ class XLPagerTabStripTests: XCTestCase {
|
|||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
self.measureBlock {
|
||||
self.measure {
|
||||
// Put the code you want to measure the time of here.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -404,7 +404,6 @@
|
|||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 2.3;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
|
|
@ -430,7 +429,7 @@
|
|||
SWIFT_INSTALL_OBJC_HEADER = YES;
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
|
|
@ -451,7 +450,7 @@
|
|||
SKIP_INSTALL = YES;
|
||||
SWIFT_INSTALL_OBJC_HEADER = YES;
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "";
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
|
@ -464,7 +463,7 @@
|
|||
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.XLPagerTabStripTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
|
|
@ -476,7 +475,7 @@
|
|||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.XLPagerTabStripTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 2.3;
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue