SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
Memory friendly UIScrollView
Yuichi Fujiki from ShopBack


28.04.2021
iOS DevScout Meetup


Apr 2021
A little about myself
• Senior iOS engineer at ShopBack


• In the
f
ield since 2011


• Hobby is to experiment with my body
2
Introduction
A little about ShopBack
3
Introduction
Agenda - Memory Friendly UIScrollView
• Image viewer


• Nested scroll view


• https://github.com/yfujiki/
iOSDevScoutMeetUpApr2021
4
Agenda
Image viewer
• What we want to build
5
Image Viewer
Simple version
• UIImageView inside UIScrollView


• Largest image for max zoom level
6
Image Viewer - Simple Version
Simple version
• Just let UIScrollView handle zoom
7
Image Viewer - Simple Version
Pitfall!
What is the issue?
• We are using too much memory
8
Image Viewer - Simple Version
• We will get pixellated view when zooming in
What if we just use small image?
9
Image Viewer - Simple Version
• Zoom level 1
Different images for different zoom levels
10
Image Viewer - CATiledLayer Version
• Zoom level 2
Different images for different zoom levels
11
Image Viewer - CATiledLayer Version
• Zoom level 4
Different images for different zoom levels
12
Image Viewer - CATiledLayer Version
CATiledLayer version
• CATiledLayer inside UIScrollView
13
Image Viewer - CATiledLayer Version
Ref: https://download.developer.apple.com/videos/wwdc_2010__sd/session_104__designing_apps_with_scroll_views.mov
Key concept about zoom levels
14
Image Viewer - CATiledLayer Version
UIScrollView
CATiledLayer
zoomScale = 1 zoomScale = 2 zoomScale = 4
levelOfDetail = 0 levelOfDetail = 1 levelOfDetail = 2
• levelsOfDetail = 3


• levelsOfDetailBias = 2
zoomScale = 1 is defined by


the original bounds of


the content view
Let’s say we set
f
irst bounds with 4 tiles…
15
Image Viewer - CATiledLayer Version
UIScrollView
CATiledLayer
zoomScale = 1 zoomScale = 2 zoomScale = 4
levelOfDetail = 0 levelOfDetail = 1 levelOfDetail = 2
zoomScale = 0.5 zoomScale = 1 zoomScale = 2
levelOfDetail = -1 levelOfDetail = 0 levelOfDetail = 1
• levelsOfDetail = 3


• levelsOfDetailBias = 1
Code - zoomScale = 1
Image Viewer - CATiledLayer Version
zoomScale = 1
Code - maximum zoom scale
Image Viewer - CATiledLayer Version
zoomScale = 4
Code - minimum zoom scale
Image Viewer - CATiledLayer Version
828x465
Code - levelsOfDetail
Image Viewer - CATiledLayer Version
Level 0
Level 1
Level 2
Code - drawRect
Image Viewer - CATiledLayer Version
Results
Image Viewer - CATiledLayer Version
UIImageView CATiledLayer
For precise measurement,


always use Instruments + real device
Nested scrollviews
• What we want to build


• UITableViews inside UIScrollView
22
Nested Scrollviews
Nested scrollviews
• What we want to build


• UITableViews inside UIScrollView
23
Nested Scrollviews
• Can’t we just use single UITableView


with multiple sections? - YES
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
• 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
Implementation
26
Nested Scrollviews - Simple Version
Top Constraint
Vertical


Constraint
Bottom Constraint
• 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
• 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
Implementation - setting content area
29
Nested Scrollviews - Scrolling Switching Version
Height


Constraint
Top Constraint
Bottom Constraint
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
Implementation - switch scrolling control
31
Nested Scrollviews - Scrolling Switching Version
Results
32
Nested Scrollviews - Scrolling Switching Version
Simple Switch Scrolling
• 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/
Implementation
34
Nested Scrollviews - Frame Controlling Version
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
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
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
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
Results
39
Nested Scrollviews - Frame Controlling Version
Simple Frame Controlling
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

Mais conteúdo relacionado

Mais procurados

Dx11 performancereloaded
Dx11 performancereloadedDx11 performancereloaded
Dx11 performancereloadedmistercteam
 
Lighting Shading by John Hable
Lighting Shading by John HableLighting Shading by John Hable
Lighting Shading by John HableNaughty Dog
 
UE4灯光应用最佳实践
UE4灯光应用最佳实践UE4灯光应用最佳实践
UE4灯光应用最佳实践Wen Lei Li
 
Physically Based Sky, Atmosphere and Cloud Rendering in Frostbite
Physically Based Sky, Atmosphere and Cloud Rendering in FrostbitePhysically Based Sky, Atmosphere and Cloud Rendering in Frostbite
Physically Based Sky, Atmosphere and Cloud Rendering in FrostbiteElectronic Arts / DICE
 
Physically Based Lighting in Unreal Engine 4
Physically Based Lighting in Unreal Engine 4Physically Based Lighting in Unreal Engine 4
Physically Based Lighting in Unreal Engine 4Lukas Lang
 
2015 데브루키 페차쿠차 "Rim Light(림라이트) 만들기"
2015 데브루키 페차쿠차 "Rim Light(림라이트) 만들기"2015 데브루키 페차쿠차 "Rim Light(림라이트) 만들기"
2015 데브루키 페차쿠차 "Rim Light(림라이트) 만들기"은아 정
 
Digital Graphics- File Formats
Digital Graphics- File FormatsDigital Graphics- File Formats
Digital Graphics- File Formatskatyfleetham
 
Unity advanced computer graphics week 02
Unity advanced computer graphics week 02Unity advanced computer graphics week 02
Unity advanced computer graphics week 02Tri Thanh
 
The Technology of Uncharted: Drake’s Fortune
The Technology of Uncharted: Drake’s FortuneThe Technology of Uncharted: Drake’s Fortune
The Technology of Uncharted: Drake’s FortuneNaughty Dog
 
Uncharted 2: Character Pipeline
Uncharted 2: Character PipelineUncharted 2: Character Pipeline
Uncharted 2: Character PipelineNaughty Dog
 
Penner pre-integrated skin rendering (siggraph 2011 advances in real-time r...
Penner   pre-integrated skin rendering (siggraph 2011 advances in real-time r...Penner   pre-integrated skin rendering (siggraph 2011 advances in real-time r...
Penner pre-integrated skin rendering (siggraph 2011 advances in real-time r...JP Lee
 
NVIDIA OpenGL and Vulkan Support for 2017
NVIDIA OpenGL and Vulkan Support for 2017NVIDIA OpenGL and Vulkan Support for 2017
NVIDIA OpenGL and Vulkan Support for 2017Mark Kilgard
 
Deferred Rendering in Killzone 2
Deferred Rendering in Killzone 2Deferred Rendering in Killzone 2
Deferred Rendering in Killzone 2Guerrilla
 
4K Checkerboard in Battlefield 1 and Mass Effect Andromeda
4K Checkerboard in Battlefield 1 and Mass Effect Andromeda4K Checkerboard in Battlefield 1 and Mass Effect Andromeda
4K Checkerboard in Battlefield 1 and Mass Effect AndromedaElectronic Arts / DICE
 
Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666Tiago Sousa
 

Mais procurados (20)

ARTE PREISTORICA
ARTE PREISTORICAARTE PREISTORICA
ARTE PREISTORICA
 
Dx11 performancereloaded
Dx11 performancereloadedDx11 performancereloaded
Dx11 performancereloaded
 
Lighting Shading by John Hable
Lighting Shading by John HableLighting Shading by John Hable
Lighting Shading by John Hable
 
UE4灯光应用最佳实践
UE4灯光应用最佳实践UE4灯光应用最佳实践
UE4灯光应用最佳实践
 
Physically Based Sky, Atmosphere and Cloud Rendering in Frostbite
Physically Based Sky, Atmosphere and Cloud Rendering in FrostbitePhysically Based Sky, Atmosphere and Cloud Rendering in Frostbite
Physically Based Sky, Atmosphere and Cloud Rendering in Frostbite
 
Van gogh VS Gauguin
Van gogh VS GauguinVan gogh VS Gauguin
Van gogh VS Gauguin
 
Physically Based Lighting in Unreal Engine 4
Physically Based Lighting in Unreal Engine 4Physically Based Lighting in Unreal Engine 4
Physically Based Lighting in Unreal Engine 4
 
2015 데브루키 페차쿠차 "Rim Light(림라이트) 만들기"
2015 데브루키 페차쿠차 "Rim Light(림라이트) 만들기"2015 데브루키 페차쿠차 "Rim Light(림라이트) 만들기"
2015 데브루키 페차쿠차 "Rim Light(림라이트) 만들기"
 
Digital Graphics- File Formats
Digital Graphics- File FormatsDigital Graphics- File Formats
Digital Graphics- File Formats
 
Unity advanced computer graphics week 02
Unity advanced computer graphics week 02Unity advanced computer graphics week 02
Unity advanced computer graphics week 02
 
Surrealismo
SurrealismoSurrealismo
Surrealismo
 
The Technology of Uncharted: Drake’s Fortune
The Technology of Uncharted: Drake’s FortuneThe Technology of Uncharted: Drake’s Fortune
The Technology of Uncharted: Drake’s Fortune
 
Uncharted 2: Character Pipeline
Uncharted 2: Character PipelineUncharted 2: Character Pipeline
Uncharted 2: Character Pipeline
 
Penner pre-integrated skin rendering (siggraph 2011 advances in real-time r...
Penner   pre-integrated skin rendering (siggraph 2011 advances in real-time r...Penner   pre-integrated skin rendering (siggraph 2011 advances in real-time r...
Penner pre-integrated skin rendering (siggraph 2011 advances in real-time r...
 
NVIDIA OpenGL and Vulkan Support for 2017
NVIDIA OpenGL and Vulkan Support for 2017NVIDIA OpenGL and Vulkan Support for 2017
NVIDIA OpenGL and Vulkan Support for 2017
 
Deferred Rendering in Killzone 2
Deferred Rendering in Killzone 2Deferred Rendering in Killzone 2
Deferred Rendering in Killzone 2
 
Hair in Tomb Raider
Hair in Tomb RaiderHair in Tomb Raider
Hair in Tomb Raider
 
4K Checkerboard in Battlefield 1 and Mass Effect Andromeda
4K Checkerboard in Battlefield 1 and Mass Effect Andromeda4K Checkerboard in Battlefield 1 and Mass Effect Andromeda
4K Checkerboard in Battlefield 1 and Mass Effect Andromeda
 
Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666
 
Landscape photography
Landscape photographyLandscape photography
Landscape photography
 

Semelhante a Memory friendly UIScrollView

New 2D World-Building, Animation & Graphics Features in Unity
New 2D World-Building, Animation & Graphics Features in UnityNew 2D World-Building, Animation & Graphics Features in Unity
New 2D World-Building, Animation & Graphics Features in UnityUnity Technologies
 
iOS Development: What's New
iOS Development: What's NewiOS Development: What's New
iOS Development: What's NewNascentDigital
 
Session 16 - Designing universal interface which used for iPad and iPhone
Session 16  -  Designing universal interface which used for iPad and iPhoneSession 16  -  Designing universal interface which used for iPad and iPhone
Session 16 - Designing universal interface which used for iPad and iPhoneVu Tran Lam
 
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
Session 15  - Working with Image, Scroll, Collection, Picker, and Web ViewSession 15  - Working with Image, Scroll, Collection, Picker, and Web View
Session 15 - Working with Image, Scroll, Collection, Picker, and Web ViewVu Tran Lam
 
storyboard時代のInterfaceBuilder
storyboard時代のInterfaceBuilderstoryboard時代のInterfaceBuilder
storyboard時代のInterfaceBuilderHiroyuki Fujikawa
 
iOS Programming 101
iOS Programming 101iOS Programming 101
iOS Programming 101rwenderlich
 
Building your first iOS app using Xamarin
Building your first iOS app using XamarinBuilding your first iOS app using Xamarin
Building your first iOS app using XamarinGill Cleeren
 
Bringing Swift into your Objective-C Projects
Bringing Swift into your Objective-C ProjectsBringing Swift into your Objective-C Projects
Bringing Swift into your Objective-C ProjectsRené Cacheaux
 
Synapse india reviews on i phone and android os
Synapse india reviews on i phone and android osSynapse india reviews on i phone and android os
Synapse india reviews on i phone and android ossaritasingh19866
 
TP_Webots_7mai2021.pdf
TP_Webots_7mai2021.pdfTP_Webots_7mai2021.pdf
TP_Webots_7mai2021.pdfkiiway01
 
Screen transitions with ease
Screen transitions with easeScreen transitions with ease
Screen transitions with easeOlivier Tassinari
 
Intro to UIKit • Made by Many
Intro to UIKit • Made by ManyIntro to UIKit • Made by Many
Intro to UIKit • Made by Manykenatmxm
 
LUMIA APP LABS #18: INTRODUCING NOKIA IMAGING SDK 1.0
LUMIA APP LABS #18: INTRODUCING NOKIA IMAGING SDK 1.0LUMIA APP LABS #18: INTRODUCING NOKIA IMAGING SDK 1.0
LUMIA APP LABS #18: INTRODUCING NOKIA IMAGING SDK 1.0Microsoft Mobile Developer
 
Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»Sigma Software
 
OpenNTF Webinar, October 2020
OpenNTF Webinar, October 2020OpenNTF Webinar, October 2020
OpenNTF Webinar, October 2020Howard Greenberg
 
FrenchKit: SwiftUI Data Flow with Redux
FrenchKit: SwiftUI Data Flow with ReduxFrenchKit: SwiftUI Data Flow with Redux
FrenchKit: SwiftUI Data Flow with ReduxThomasRicouard
 
Head first iOS programming
Head first iOS programmingHead first iOS programming
Head first iOS programmingtedzhaoxa
 

Semelhante a Memory friendly UIScrollView (20)

New 2D World-Building, Animation & Graphics Features in Unity
New 2D World-Building, Animation & Graphics Features in UnityNew 2D World-Building, Animation & Graphics Features in Unity
New 2D World-Building, Animation & Graphics Features in Unity
 
iOS Development: What's New
iOS Development: What's NewiOS Development: What's New
iOS Development: What's New
 
Session 16 - Designing universal interface which used for iPad and iPhone
Session 16  -  Designing universal interface which used for iPad and iPhoneSession 16  -  Designing universal interface which used for iPad and iPhone
Session 16 - Designing universal interface which used for iPad and iPhone
 
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
Session 15  - Working with Image, Scroll, Collection, Picker, and Web ViewSession 15  - Working with Image, Scroll, Collection, Picker, and Web View
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
 
storyboard時代のInterfaceBuilder
storyboard時代のInterfaceBuilderstoryboard時代のInterfaceBuilder
storyboard時代のInterfaceBuilder
 
iOS Programming 101
iOS Programming 101iOS Programming 101
iOS Programming 101
 
Building your first iOS app using Xamarin
Building your first iOS app using XamarinBuilding your first iOS app using Xamarin
Building your first iOS app using Xamarin
 
Bringing Swift into your Objective-C Projects
Bringing Swift into your Objective-C ProjectsBringing Swift into your Objective-C Projects
Bringing Swift into your Objective-C Projects
 
Synapse india reviews on i phone and android os
Synapse india reviews on i phone and android osSynapse india reviews on i phone and android os
Synapse india reviews on i phone and android os
 
Synapse india mobile apps update
Synapse india mobile apps updateSynapse india mobile apps update
Synapse india mobile apps update
 
Animation in iOS
Animation in iOSAnimation in iOS
Animation in iOS
 
TP_Webots_7mai2021.pdf
TP_Webots_7mai2021.pdfTP_Webots_7mai2021.pdf
TP_Webots_7mai2021.pdf
 
Screen transitions with ease
Screen transitions with easeScreen transitions with ease
Screen transitions with ease
 
Intro to UIKit • Made by Many
Intro to UIKit • Made by ManyIntro to UIKit • Made by Many
Intro to UIKit • Made by Many
 
LUMIA APP LABS #18: INTRODUCING NOKIA IMAGING SDK 1.0
LUMIA APP LABS #18: INTRODUCING NOKIA IMAGING SDK 1.0LUMIA APP LABS #18: INTRODUCING NOKIA IMAGING SDK 1.0
LUMIA APP LABS #18: INTRODUCING NOKIA IMAGING SDK 1.0
 
Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»
 
OpenNTF Webinar, October 2020
OpenNTF Webinar, October 2020OpenNTF Webinar, October 2020
OpenNTF Webinar, October 2020
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
FrenchKit: SwiftUI Data Flow with Redux
FrenchKit: SwiftUI Data Flow with ReduxFrenchKit: SwiftUI Data Flow with Redux
FrenchKit: SwiftUI Data Flow with Redux
 
Head first iOS programming
Head first iOS programmingHead first iOS programming
Head first iOS programming
 

Último

%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 

Último (20)

%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 

Memory friendly UIScrollView

  • 1. Memory friendly UIScrollView Yuichi Fujiki from ShopBack 28.04.2021 iOS DevScout Meetup 
 Apr 2021
  • 2. A little about myself • Senior iOS engineer at ShopBack • In the f ield since 2011 • Hobby is to experiment with my body 2 Introduction
  • 3. A little about ShopBack 3 Introduction
  • 4. Agenda - Memory Friendly UIScrollView • Image viewer • Nested scroll view • https://github.com/yfujiki/ iOSDevScoutMeetUpApr2021 4 Agenda
  • 5. Image viewer • What we want to build 5 Image Viewer
  • 6. Simple version • UIImageView inside UIScrollView • Largest image for max zoom level 6 Image Viewer - Simple Version
  • 7. Simple version • Just let UIScrollView handle zoom 7 Image Viewer - Simple Version Pitfall!
  • 8. What is the issue? • We are using too much memory 8 Image Viewer - Simple Version
  • 9. • We will get pixellated view when zooming in What if we just use small image? 9 Image Viewer - Simple Version
  • 10. • Zoom level 1 Different images for different zoom levels 10 Image Viewer - CATiledLayer Version
  • 11. • Zoom level 2 Different images for different zoom levels 11 Image Viewer - CATiledLayer Version
  • 12. • Zoom level 4 Different images for different zoom levels 12 Image Viewer - CATiledLayer Version
  • 13. CATiledLayer version • CATiledLayer inside UIScrollView 13 Image Viewer - CATiledLayer Version Ref: https://download.developer.apple.com/videos/wwdc_2010__sd/session_104__designing_apps_with_scroll_views.mov
  • 14. Key concept about zoom levels 14 Image Viewer - CATiledLayer Version UIScrollView CATiledLayer zoomScale = 1 zoomScale = 2 zoomScale = 4 levelOfDetail = 0 levelOfDetail = 1 levelOfDetail = 2 • levelsOfDetail = 3 • levelsOfDetailBias = 2 zoomScale = 1 is defined by 
 the original bounds of 
 the content view
  • 15. Let’s say we set f irst bounds with 4 tiles… 15 Image Viewer - CATiledLayer Version UIScrollView CATiledLayer zoomScale = 1 zoomScale = 2 zoomScale = 4 levelOfDetail = 0 levelOfDetail = 1 levelOfDetail = 2 zoomScale = 0.5 zoomScale = 1 zoomScale = 2 levelOfDetail = -1 levelOfDetail = 0 levelOfDetail = 1 • levelsOfDetail = 3 • levelsOfDetailBias = 1
  • 16. Code - zoomScale = 1 Image Viewer - CATiledLayer Version zoomScale = 1
  • 17. Code - maximum zoom scale Image Viewer - CATiledLayer Version zoomScale = 4
  • 18. Code - minimum zoom scale Image Viewer - CATiledLayer Version 828x465
  • 19. Code - levelsOfDetail Image Viewer - CATiledLayer Version Level 0 Level 1 Level 2
  • 20. Code - drawRect Image Viewer - CATiledLayer Version
  • 21. Results Image Viewer - CATiledLayer Version UIImageView CATiledLayer For precise measurement, 
 always use Instruments + real device
  • 22. Nested scrollviews • What we want to build • UITableViews inside UIScrollView 22 Nested Scrollviews
  • 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
  • 26. Implementation 26 Nested Scrollviews - Simple Version Top Constraint Vertical 
 Constraint Bottom Constraint
  • 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
  • 32. Results 32 Nested Scrollviews - Scrolling Switching Version Simple Switch Scrolling
  • 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/
  • 34. Implementation 34 Nested Scrollviews - Frame Controlling Version
  • 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
  • 39. Results 39 Nested Scrollviews - Frame Controlling Version Simple Frame Controlling
  • 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