Swiftpack.co - Package - epitonium/EARestrictedScrollView

EARestrictedScrollView

Swift Package

Description

Swift Package 📦 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.

Installation

Use Swift Package Manager to install.

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.

let subviews = restrictedScrollView.containedSubviews

Author

Created and maintained by Evgeny Aleksandrov (@ealeksandrov). Refactored and adapted for use with the Swift Package Manager by Vitalis Gkirsas.

License

EAIntroView is distributed under the terms and conditions of the MIT license.

Github

link
Stars: 0

Dependencies

Used By

Total: 0