GithubHelp home page GithubHelp logo

ealeksandrov / earestrictedscrollview Goto Github PK

View Code? Open in Web Editor NEW
65.0 5.0 18.0 12.13 MB

UIScrollView sublass with ability to restrict scrolling area

License: MIT License

Ruby 10.57% Swift 89.43%
ios uiscrollview swift

earestrictedscrollview's Introduction

EARestrictedScrollView

CI Status Version SwiftPM compatible Carthage compatible License Platform

DemoGIF

UIScrollView sublass with ability to restrict scrolling area.

In plain UIScrollView only contentSize can be changed, but not the origin of scrolling area. This simple and universal solution allows to restrict scrolling area with CGRect.

For objective-c projects you can use version 1.1.0.

Installation

You can setup EARestrictedScrollView using Carthage, CocoaPods, Swift Package Manager or completely manually.

Carthage

  1. Add EARestrictedScrollView to your project's Cartfile:

    github "ealeksandrov/EARestrictedScrollView"
  2. Run carthage update in your project directory.

  3. On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop EARestrictedScrollView.framework from the Carthage/Build/iOS/ folder on disk.

  4. On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script with the following contents:

    /usr/local/bin/carthage copy-frameworks

    and add the path to the framework under “Input Files”:

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

CocoaPods

  1. Add EARestrictedScrollView to your project's Podfile:

    pod 'EARestrictedScrollView', '~> 2.1.0'
  2. Run pod update or pod install in your project directory.

Swift Package Manager

  1. Add EARestrictedScrollView to your project’s ‘Swift Packages’ section or Package.swift:
.package(url: "https://github.com/ealeksandrov/EARestrictedScrollView.git", from: "2.1.0")

Setting Up Manually

  1. Clone EARestrictedScrollView from Github.

  2. Copy and add EARestrictedScrollView header and implementation to your project.

  3. You can now use EARestrictedScrollView by adding the following import:

    import EARestrictedScrollView

How To Use It

Can be created from code as usual:

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
    }

Or from Interface Builder:

IB screenshot

Update scrolling area with new restrictionArea property. Reset restriction with passing CGRectZero to restrictionArea.

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

To access subviews use containedSubviews property. It was added in version 0.2.0 since subviews override caused some troubles with autolayout.

let subviews = restrictedScrollView.containedSubviews

Author

Created and maintained by Evgeny Aleksandrov (@ealeksandrov).

License

EARestrictedScrollView is available under the MIT license. See the LICENSE.md file for more info.

earestrictedscrollview's People

Contributors

ealeksandrov avatar rwgrier avatar woxtu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.