SilentScrolly 1.0.8

SilentScrolly 1.0.8

Takuma Horiuchi 维护。



Platform Swift Cocoapods Carthage compatible License

概述

滚动以隐藏导航栏、标签栏和工具栏。

特性

UIView 添加过多的 UIGestureRecognizer 使得处理变得困难,因此它被通过 UIScrollViewDelegate 处理。

要求

  • Xcode 9.0+
  • iOS 10+
  • Swift 4.0+

安装

CocoaPods

pod 'SilentScrolly'

Carthage

github "horitaku46/SilentScrolly"

使用说明

更多详情请参阅示例

《1》 如果您想更改statusBar的颜色,请在UINavigationController中添加func statusBarStyle(showStyle: UIStatusBarStyle, hideStyle: UIStatusBarStyle)

import UIKit

final class NavigationController: UINavigationController {

    override var preferredStatusBarStyle: UIStatusBarStyle {
        return topViewController?.preferredStatusBarStyle ?? .default
    }
}

《2》 请按以下方式描述。

import UIKit

final class TableViewController: UIViewController, SilentScrollable {

    override var preferredStatusBarStyle: UIStatusBarStyle {
        return statusBarStyle(showStyle: .lightContent, hideStyle: .default) // Optional
    }

    @IBOutlet weak var tableView: UITableView! {
        didSet {
            tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
            tableView.delegate = self
            tableView.dataSource = self
        }
    }

    var silentScrolly: SilentScrolly?

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        silentDidLayoutSubviews()
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        configureSilentScrolly(tableView, followBottomView: tabBarController?.tabBar)
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        silentWillDisappear()
    }

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        silentDidDisappear()
    }

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        silentWillTranstion()
    }
}

extension TableViewController: UITableViewDelegate {

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        silentDidScroll()
    }

    func scrollViewDidZoom(_ scrollView: UIScrollView) {
        silentDidZoom() // Optional
    }

    func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
        showNavigationBar() // Optional
        return true
    }
}

extension TableViewController: UITableViewDataSource {

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 100
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
        cell.textLabel?.text = "Row: \(indexPath.row)"
        return cell
    }
}

作者

Takuma Horiuchi

许可证

SilentScrolly遵循MIT许可证。有关更多信息,请参阅许可证文件。