23. Nested scrollviews
• What we want to build
• UITableViews inside UIScrollView
23
Nested Scrollviews
• Can’t we just use single UITableView
with multiple sections? - YES
24. Nested scrollviews
• In general, we could face complex layout requirements
that demands nested scrollview
24
Nested Scrollviews
• Can’t we use UICollectionViewCompositionalLayout?
• YES!!! But with limitations
• >= iOS 13
• Some complex layouts are still not possible
25. • Make UITableView frame to
be the same size as it’s content size
• Make UITableViews frames to
f
ill up
entire contentSize of UIScrollView
• UIScrollView (gray) will control all scrolling
Simple version
25
Nested Scrollviews - Simple Version
27. • UITableView’s cell won’t reuse
• All cells for both UITableViews will be
loaded into memory
What is the issue?
27
Nested Scrollviews - Simple Version
28. • Outer ScrollView handles scroll when
both TableViews are visible
• Let the inner TableView handle scroll when
the TableView occupies the view
Switch Scrolling Control
28
Nested Scrollviews - Scrolling Switching Version
• Setting the content area properly
• Allow both gesture recognisers to work
• Switching scrolling control at the right timing
29. Implementation - setting content area
29
Nested Scrollviews - Scrolling Switching Version
Height
Constraint
Top Constraint
Bottom Constraint
30. Implementation - enable gesture
30
Nested Scrollviews - Scrolling Switching Version
• Without this, UITableView (inner) captures all gestures and UIScrollView
(outer) does not get any gesture at all
31. Implementation - switch scrolling control
31
Nested Scrollviews - Scrolling Switching Version
33. • Outer ScrollView handles scroll all the time
• As the viewport moves, calculate the frame
of each tableview to
f
it inside the viewport
Control the frames
33
Nested Scrollviews - Frame Controlling Version
Ref: https://oleb.net/blog/2014/05/scrollviews-inside-scrollviews/
35. Implementation
35
Nested Scrollviews - Frame Controlling Version
Bounds
of
Scroll
View
Content
Area
of
Scroll
View
Content
Area
of
Table
View
Frame
of
Table
View
36. Implementation
36
Nested Scrollviews - Frame Controlling Version
Bounds
of
Scroll
View
Content
Area
of
Scroll
View
Content
Area
of
Table
View
Frame
of
Table
View
37. Implementation
37
Nested Scrollviews - Frame Controlling Version
Bounds
of
Scroll
View
Content
Area
of
Scroll
View
Content
Area
of
Table
View
Frame
of
Table
View
38. Implementation
38
Nested Scrollviews - Frame Controlling Version
Bounds
of
Scroll
View
Content
Area
of
Scroll
View
Content
Area
of
Table
View
Frame
of
Table
View
40. Conclusions
• Naive usage of UIScrollView leaves a lot of margin to
improve memory usage
• Keep experimenting. Even going through already
treaded path yourself will give you great insight
• https://github.com/yfujiki/iOSDevScoutMeetUpApr2021
40
Conclusion