TabPageScrollViewController 1.1.0

TabPageScrollViewController 1.1.0

Keisuke Yamagishi 维护。



  • 作者:keisuke
  • keisuke

TabScrollPageViewController

概述

屏幕顶部的标签栏与页面滚动同步移动。

当您按压标签时,它将转换到您按下的页面。

如果您想使用 UIPageViewController 构建与屏幕顶部标签栏同步的应用程序,这将非常棒。

Cocoapods

CocoaPods 是 Cocoa 项目的依赖项管理器。您可以按照以下命令安装它

$ gem install cocoapods

要使用 CocoaPods 将 TabPageScrollViewController 集成到您的 Xcode 项目中,在您的 Podfile 中指定它

vi ./Podfile
target 'MyApp' do
  pod 'TabPageScrollViewController'
end

使用它

通过 SSH:对于那些计划定期直接提交的用户,通过 SSH 克隆可能提供更好的体验(需要将 SSH 密钥上传到 GitHub)

$ git clone git remote add origin [email protected]:keisukeYamagishi/TabPageScrollViewController.git

通过 https:对于仅检查出源的只想读取的用户,HTTPS 工作得最好

$ git clone https://github.com/keisukeYamagishi/TabPageScrollViewController.git

示例代码

继承自 TabPageScrollViewController

//
//  RootViewController.swift
//  TabPageScrollViewController
//
//  Created by Shichimitoucarashi on 1/17/19.
//  Copyright © 2019 Shichimitoucarashi. All rights reserved.
//

import UIKit
import TabPageScrollViewController

@available(iOS 11.0, *)
class RootViewControler:TabPageScrollViewController {
    
    override func viewDidLoad() {
        
        self.navigationController?.navigationBar.topItem?.title = "TabPage app demo"
        
        self.delegate = self
        
        let vc1:ViewController = storyboard!.instantiateViewController(withIdentifier: ViewController.identifer) as! ViewController
        vc1.number = 1
        let vc2:ViewController = storyboard!.instantiateViewController(withIdentifier: ViewController.identifer) as! ViewController
        vc2.number = 2
        let vc3:ViewController = storyboard!.instantiateViewController(withIdentifier: ViewController.identifer) as! ViewController
        vc3.number = 3
        let vc4:ViewController = storyboard!.instantiateViewController(withIdentifier: ViewController.identifer) as! ViewController
        vc4.number = 4
        let vc5:ViewController = storyboard!.instantiateViewController(withIdentifier: ViewController.identifer) as! ViewController
        vc5.number = 5
        let vc6:ViewController = storyboard!.instantiateViewController(withIdentifier: ViewController.identifer) as! ViewController
        vc6.number = 6
        let vc7:ViewController = storyboard!.instantiateViewController(withIdentifier: ViewController.identifer) as! ViewController
        vc7.number = 7
        let vc8:ViewController = storyboard!.instantiateViewController(withIdentifier: ViewController.identifer) as! ViewController
        vc8.number = 8
        let vc9:ViewController = storyboard!.instantiateViewController(withIdentifier: ViewController.identifer) as! ViewController
        vc9.number = 9
        let vc10:ViewController = storyboard!.instantiateViewController(withIdentifier: ViewController.identifer) as! ViewController
        vc10.number = 10
        let vc11:ViewController = storyboard!.instantiateViewController(withIdentifier: ViewController.identifer) as! ViewController
        vc11.number = 11
        
        self.tabItems = [TabItem(title: "Firsrt",vc: vc1),
                         TabItem(title: "Second",vc: vc2),
                         TabItem(title: "Third",vc: vc3),
                         TabItem(title: "Four",vc: vc4),
                         TabItem(title: "Five",vc: vc5),
                         TabItem(title: "Six",vc: vc6),
                         TabItem(title: "Seven",vc: vc7),
                         TabItem(title: "Eight",vc: vc8),
                         TabItem(title: "Nine",vc: vc9),
                         TabItem(title: "Ten",vc: vc10),
                         TabItem(title: "Eleven",vc: vc11)]
        
        self.view.backgroundColor = .white
        
        super.viewDidLoad()
    }
}

@available(iOS 11.0, *)
extension RootViewControler:TabPageDelegate{
    
    func willScrollPage(index: Int, viewController: UIViewController) {
        
        let vc:ViewController = viewController as! ViewController
        
        print ("index: \(index) viewController: \(vc.number)")
    }
    
    func didScrollPage(index: Int, viewController: UIViewController) {
        
        let vc:ViewController = viewController as! ViewController
        
        print ("index: \(index) viewController: \(vc.number)")
    }
    
    
    func tabChangeNotify(index: IndexPath, vc: UIViewController) {
        print ("index: \(index)")
    }
    
    func moveNavigationNotify(index: IndexPath) {
        print ("index: \(index)")
    }
}

非常好😏