Skip to content

A very simple UIKit implementation of nested UIScrollViews

Notifications You must be signed in to change notification settings

Thisura98/ios-nested-scrollviews

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iOS Simple Nested Scrollviews

Nested scrollviews are problematic in UIKit because of the following reasons.

  1. Nested scrollview's scroll gestures are sometimes 'stolen' by outer scrollview.
  2. Smooth scroll transition between scrollviews is not built-in.
  3. Fixing this requires libraries or hijacking scroll gestures in the UIScrollViewDelegate.

The proposed solution for achieving this in UIKit is as follows.

  1. Set the outer scrollview's class to OuterScroll.
  2. Set the inner scrollview's class to InnerScroll.
  3. Add the code, OuterScroll.Reference.iScroll = <InnerScroll instance>

Both OuterScroll and InnerScroll inherit from UIScrollView.

Usage

1. Setup two UIScrollViews where the nested one is inside the outer one.

2. Create the relationship between Outer and Inner UIScrollViews

class ViewController: UIViewController {

    @IBOutlet private weak var outerScroll: OuterScroll!
    @IBOutlet private weak var innerScroll: InnerScroll!
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        // Set references
        OuterScroll.Reference.iScroll = innerScroll
    }
}

About

A very simple UIKit implementation of nested UIScrollViews

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages