EARestrictedScrollView 2.1.0

EARestrictedScrollView 2.1.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2020年12月
SPM支持SPM

Evgeny Aleksandrov维护。




EARestrictedScrollView

CI Status Version SwiftPM compatible Carthage compatible License Platform

DemoGIF

UIScrollView子类,具有限制滚动区域的功能。

在普通的UIScrollView中,只能更改contentSize,而不能更改滚动区域的起点。这个简单且通用的解决方案允许使用CGRect限制滚动区域。

对于Objective-C项目,您可以使用1.1.0版本。

安装

您可以使用CarthageCocoaPodsSwift Package Manager完全手动设置EARestrictedScrollView。

Carthage

  1. 将EARestrictedScrollView添加到项目的Cartfile

    github "ealeksandrov/EARestrictedScrollView"
  2. 在项目目录中运行carthage update

  3. 在您应用程序目标的“常规”设置选项卡中,在“链接框架和库”部分,从磁盘上的Carthage/Build/iOS/文件夹中将EARestrictedScrollView.framework拖放到“链接框架和库”列表中。

  4. 在你的应用的“构建阶段”设置标签页中,点击“+”图标,选择“新建运行脚本阶段”。创建一个包含以下内容的运行脚本

    /usr/local/bin/carthage copy-frameworks

    并在“输入文件”下添加框架的路径

    $(SRCROOT)/Carthage/Build/iOS/EARestrictedScrollView.framework

CocoaPods

  1. 将 EARestrictedScrollView 添加到你的 Podfile 项目中。

    pod 'EARestrictedScrollView', '~> 2.1.0'
  2. 在你的项目目录中运行 pod updatepod install

Swift 包管理器

  1. 将 EARestrictedScrollView 添加到你的项目“Swift 包”部分或 Package.swift 文件。
.package(url: "https://github.com/ealeksandrov/EARestrictedScrollView.git", from: "2.1.0")

手动设置

  1. 从 Github 克隆 EARestrictedScrollView。

  2. 复制并添加 EARestrictedScrollView 头文件和实现代码到你的项目中。

  3. 现在你可以通过添加以下导入来使用 EARestrictedScrollView:

    import EARestrictedScrollView

使用方法

可以从代码中创建,就像通常一样

override func viewDidLoad() {
        super.viewDidLoad()
        
        restrictedScrollView = EARestrictedScrollView(frame: view.bounds)
        restrictedScrollView.alwaysBounceVertical = true
        restrictedScrollView.alwaysBounceHorizontal = true
        view.addSubview(restrictedScrollView)
        
        let imageView = UIImageView(image: UIImage(named: "milky-way"))
        restrictedScrollView.addSubview(imageView)
        restrictedScrollView.contentSize = imageView.frame.size
    }

或从 Interface Builder 创建

IB screenshot

使用新的 restrictionArea 属性更新滚动区域。将通过将 CGRectZero 传递给 restrictionArea 来重置限制。

func flipSwitch(sender: UISwitch) {
        if sender.on {
            restrictedScrollView.restrictionArea = sender.superview!.frame
        } else {
            restrictedScrollView.restrictionArea = CGRectZero
        }
    }

要访问子视图,请使用 containedSubviews 属性。由于 subviews 重写引起了一些 自动布局问题,因此它在 0.2.0 版本中添加。

let subviews = restrictedScrollView.containedSubviews

作者

由 Evgeny Aleksandrov 创建和维护(@ealeksandrov)。

许可证

EARestrictedScrollView 在MIT许可证下可用。更多信息请参阅LICENSE.md文件。