SlideShare ist ein Scribd-Unternehmen logo
1 von 24
CATiledLayer


Jesse Collis, Melbourne Cocoaheads, February 2012
       jesse@jcmultimedia.com.au / @sirjec
CATiledLayer
Tiled Views in 2009

           Tiled UIScrollViews

           iOS 3 Compatibility

                @2x.png
CATiledLayer in iOS4
My main goals

• CATiledLayer in a zooming scrollView
• Seamless integration into iOS4+
• Seamless integration between retina / non-
  retina screens
• provide only one sized tile (not @2x)
Success
Finally...
Success
Finally...
Here’s what I learnt
• UIViews are backed by CALayers
• All good CALayer documentation is OSX
  based
• NSView is not backed by CALayer
• drawRect: (more or less) equals
  drawLayer:inContext delegate method in
  OSX docs
What I learnt cont...
• Core Graphics helps with high resolution
  screens most of the time

• CATiledLayer is just a CALayer subclass
 • It’s instantiated as a UIView’s layer
 • It uses drawRect:
 • contentScale is set by it’s UIView
Basic Implementation
+(Class)layerClass
{
  return [CATiledLayer class];
}

- (id)initWithFrame:(CGRect)frame
{
  ...
  [(CATiledLayer *)self.layer setLevelsOfDetail:1];
  [(CATiledLayer *)self.layer setLevelsOfDetailBias:3];
  ...
}

- (void)drawRect:(CGRect)rect
{
  CGContextRef c = UIGraphicsGetCurrentContext();
  CGFloat scale = CGContextGetCTM(c).a;

    NSInteger col = (CGRectGetMinX(rect) * scale) / self.tileSize.width;
    NSInteger row = (CGRectGetMinY(rect) * scale) / self.tileSize.height;

    UIImage *tile_image = [self.tileSource tiledView:self
                                         imageForRow:row
                                    column:col scale:scale];
    [tile_image drawInRect:rect];
}
LOD & LODB

• LOD is the number of levels it will ask you
  for as you zoom out
• LODB is the number of levels it will use as
  you zoom in
UIScrollView zoomScale vs.
         CATiledLayer LODB


• zoomScale is measured on a linear scale
• zoomScale has an exponential effect on
  pixels
• Each LODB/LOD is a power of two more
  or less than the previous level of detail.
UIScrollView zoomScale vs.
         CATiledLayer LODB


• zoomScale is measured on a linear scale
• zoomScale has an exponential effect on
  pixels
• Each LODB/LOD is a power of two more
  or less than the previous level of detail.
Some Notes
• Setting LOD and LODB to 0 causes a blank
  view
• Setting LOD and LODB to 1 seems to be
  undefined behaviour
• Setting LOD to 1, and LODB > 1 is fine,
  but I like to set LOD to 0 if I’m using
  LODB.
Code Time




JCTiledLayer
Retina Display
Apple’s docs on Supporting High Resolution screens:

[You] may need to adjust [Core Animation Layers] drawing code to account for
scale factors. Normally, when you draw in your view’s drawRect: method … of
the layer’s delegate, the system automatically adjusts the graphics context to
account for scale factors. However, knowing or changing that scale factor
might still be necessary when your view does one of the following:

 • Creates additional Core Animation layers with different scale factors and
   composites them into its own content.
A few things you need to do
•   layer.contentsScale == 2 so everything in pixel land
    is squared

•   Multiply the original tileSize by the contentsScale

•   Multiply drawRect: rect by the context scale giving
    us our 512x512 tileSize

•   divide rect by contentsScale to give us rect with
    256x256 dimensions

•   rect origin can now be used to grab the right tile

•   draw said tile it into rect; Core Graphics will do
    the rest
What’s next

• Add UIGestureRecognizer support for
  more map-like features
• Overlay support
• Replace UIImages with vectors or SVG
  drawing
JCTiledView is on
     Github


     •   github.com/jessedc/JCTiledScrollView
Thanks!

Jesse Collis
jesse@jcmultimedia.com.au
twitter.com/sirjec

Weitere ähnliche Inhalte

Was ist angesagt?

DevOps à l'échelle: ce que l'on a fait, ce que l'on a appris chez Societe Gen...
DevOps à l'échelle: ce que l'on a fait, ce que l'on a appris chez Societe Gen...DevOps à l'échelle: ce que l'on a fait, ce que l'on a appris chez Societe Gen...
DevOps à l'échelle: ce que l'on a fait, ce que l'on a appris chez Societe Gen...Adrien Blind
 
Solid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJSSolid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJSRafael Casuso Romate
 
Developing Apps With React Native
Developing Apps With React NativeDeveloping Apps With React Native
Developing Apps With React NativeAlvaro Viebrantz
 
Design systems : Bench et reco sur les outils
Design systems : Bench et reco sur les outilsDesign systems : Bench et reco sur les outils
Design systems : Bench et reco sur les outilsIdean France
 
[GPG스터디] 1.0 데이터 주도적 설계의 마법
[GPG스터디] 1.0 데이터 주도적 설계의 마법[GPG스터디] 1.0 데이터 주도적 설계의 마법
[GPG스터디] 1.0 데이터 주도적 설계의 마법Sehyeon Nam
 
How To Become A DevOps Engineer | Who Is A DevOps Engineer? | DevOps Engineer...
How To Become A DevOps Engineer | Who Is A DevOps Engineer? | DevOps Engineer...How To Become A DevOps Engineer | Who Is A DevOps Engineer? | DevOps Engineer...
How To Become A DevOps Engineer | Who Is A DevOps Engineer? | DevOps Engineer...Simplilearn
 
코드 생성을 사용해 개발 속도 높이기 NDC2011
코드 생성을 사용해 개발 속도 높이기 NDC2011코드 생성을 사용해 개발 속도 높이기 NDC2011
코드 생성을 사용해 개발 속도 높이기 NDC2011Esun Kim
 
そんなリザルトキャッシュで大丈夫か? #jjug
そんなリザルトキャッシュで大丈夫か? #jjugそんなリザルトキャッシュで大丈夫か? #jjug
そんなリザルトキャッシュで大丈夫か? #jjugToshiaki Maki
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painSander Mak (@Sander_Mak)
 
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍Chris Ohk
 
CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~
CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~ CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~
CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~ SEGADevTech
 
Automated Dependency Updates with Renovate
Automated Dependency Updates with RenovateAutomated Dependency Updates with Renovate
Automated Dependency Updates with RenovateTeppei Sato
 

Was ist angesagt? (20)

Angular
AngularAngular
Angular
 
React Tech Salon
React Tech SalonReact Tech Salon
React Tech Salon
 
DevSecOps
DevSecOpsDevSecOps
DevSecOps
 
.Net Core 1.0 vs .NET Framework
.Net Core 1.0 vs .NET Framework.Net Core 1.0 vs .NET Framework
.Net Core 1.0 vs .NET Framework
 
DevOps à l'échelle: ce que l'on a fait, ce que l'on a appris chez Societe Gen...
DevOps à l'échelle: ce que l'on a fait, ce que l'on a appris chez Societe Gen...DevOps à l'échelle: ce que l'on a fait, ce que l'on a appris chez Societe Gen...
DevOps à l'échelle: ce que l'on a fait, ce que l'on a appris chez Societe Gen...
 
Solid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJSSolid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJS
 
Architecture of MessagePack
Architecture of MessagePackArchitecture of MessagePack
Architecture of MessagePack
 
Developing Apps With React Native
Developing Apps With React NativeDeveloping Apps With React Native
Developing Apps With React Native
 
Design systems : Bench et reco sur les outils
Design systems : Bench et reco sur les outilsDesign systems : Bench et reco sur les outils
Design systems : Bench et reco sur les outils
 
C sharp
C sharpC sharp
C sharp
 
[GPG스터디] 1.0 데이터 주도적 설계의 마법
[GPG스터디] 1.0 데이터 주도적 설계의 마법[GPG스터디] 1.0 데이터 주도적 설계의 마법
[GPG스터디] 1.0 데이터 주도적 설계의 마법
 
SRE & Kubernetes
SRE & KubernetesSRE & Kubernetes
SRE & Kubernetes
 
How To Become A DevOps Engineer | Who Is A DevOps Engineer? | DevOps Engineer...
How To Become A DevOps Engineer | Who Is A DevOps Engineer? | DevOps Engineer...How To Become A DevOps Engineer | Who Is A DevOps Engineer? | DevOps Engineer...
How To Become A DevOps Engineer | Who Is A DevOps Engineer? | DevOps Engineer...
 
코드 생성을 사용해 개발 속도 높이기 NDC2011
코드 생성을 사용해 개발 속도 높이기 NDC2011코드 생성을 사용해 개발 속도 높이기 NDC2011
코드 생성을 사용해 개발 속도 높이기 NDC2011
 
DevSecOps .pptx
DevSecOps .pptxDevSecOps .pptx
DevSecOps .pptx
 
そんなリザルトキャッシュで大丈夫か? #jjug
そんなリザルトキャッシュで大丈夫か? #jjugそんなリザルトキャッシュで大丈夫か? #jjug
そんなリザルトキャッシュで大丈夫か? #jjug
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
 
CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~
CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~ CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~
CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~
 
Automated Dependency Updates with Renovate
Automated Dependency Updates with RenovateAutomated Dependency Updates with Renovate
Automated Dependency Updates with Renovate
 

Ähnlich wie Implementing CATiledLayer

Hi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextHi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextMugunth Kumar
 
React Native: Introduction
React Native: IntroductionReact Native: Introduction
React Native: IntroductionInnerFood
 
The Great CALayer Tour
The Great CALayer TourThe Great CALayer Tour
The Great CALayer TourScott Gardner
 
JS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-NativeJS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-NativeJSFestUA
 
iOS Development: What's New
iOS Development: What's NewiOS Development: What's New
iOS Development: What's NewNascentDigital
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015Hossein Zahed
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAmir Barylko
 
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your ApplicationsThe Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your Applicationsbalassaitis
 
iOS Coding Best Practices
iOS Coding Best PracticesiOS Coding Best Practices
iOS Coding Best PracticesJean-Luc David
 
Rails and iOS with RestKit
Rails and iOS with RestKitRails and iOS with RestKit
Rails and iOS with RestKitAndrew Culver
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGLGary Yeh
 
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
 
Designing True Cross-Platform Apps
Designing True Cross-Platform AppsDesigning True Cross-Platform Apps
Designing True Cross-Platform AppsFITC
 
From Legacy Database to Domain Layer Using a New Cincom VisualWorks Tool
From Legacy Database to Domain Layer Using a New Cincom VisualWorks ToolFrom Legacy Database to Domain Layer Using a New Cincom VisualWorks Tool
From Legacy Database to Domain Layer Using a New Cincom VisualWorks ToolESUG
 
MongoDB Charts Meetup - 7-24-2018
MongoDB Charts Meetup - 7-24-2018MongoDB Charts Meetup - 7-24-2018
MongoDB Charts Meetup - 7-24-2018Jay Gordon
 

Ähnlich wie Implementing CATiledLayer (20)

Hi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextHi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreText
 
React Native: Introduction
React Native: IntroductionReact Native: Introduction
React Native: Introduction
 
The Great CALayer Tour
The Great CALayer TourThe Great CALayer Tour
The Great CALayer Tour
 
JS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-NativeJS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-Native
 
Core animation
Core animationCore animation
Core animation
 
iOS Development: What's New
iOS Development: What's NewiOS Development: What's New
iOS Development: What's New
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescript
 
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your ApplicationsThe Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
 
Cocos2d for beginners
Cocos2d for beginnersCocos2d for beginners
Cocos2d for beginners
 
iOS Coding Best Practices
iOS Coding Best PracticesiOS Coding Best Practices
iOS Coding Best Practices
 
Rails and iOS with RestKit
Rails and iOS with RestKitRails and iOS with RestKit
Rails and iOS with RestKit
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGL
 
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
 
Designing True Cross-Platform Apps
Designing True Cross-Platform AppsDesigning True Cross-Platform Apps
Designing True Cross-Platform Apps
 
Synapse india mobile apps update
Synapse india mobile apps updateSynapse india mobile apps update
Synapse india mobile apps update
 
From Legacy Database to Domain Layer Using a New Cincom VisualWorks Tool
From Legacy Database to Domain Layer Using a New Cincom VisualWorks ToolFrom Legacy Database to Domain Layer Using a New Cincom VisualWorks Tool
From Legacy Database to Domain Layer Using a New Cincom VisualWorks Tool
 
IOS Storyboards
IOS StoryboardsIOS Storyboards
IOS Storyboards
 
MongoDB Charts Meetup - 7-24-2018
MongoDB Charts Meetup - 7-24-2018MongoDB Charts Meetup - 7-24-2018
MongoDB Charts Meetup - 7-24-2018
 
COMP340 TOPIC 4 THREE.JS.pptx
COMP340 TOPIC 4 THREE.JS.pptxCOMP340 TOPIC 4 THREE.JS.pptx
COMP340 TOPIC 4 THREE.JS.pptx
 

Mehr von Jesse Collis

Preparing for iOS 9 - Melbourne Cocoaheads June 2015
Preparing for iOS 9 - Melbourne Cocoaheads June 2015Preparing for iOS 9 - Melbourne Cocoaheads June 2015
Preparing for iOS 9 - Melbourne Cocoaheads June 2015Jesse Collis
 
A Brief History of Melbourne Cocoaheads - May 2013
A Brief History of Melbourne Cocoaheads - May 2013A Brief History of Melbourne Cocoaheads - May 2013
A Brief History of Melbourne Cocoaheads - May 2013Jesse Collis
 
Epic Refactorings - Melbourne Cocoaheads June 2011
Epic Refactorings - Melbourne Cocoaheads June 2011Epic Refactorings - Melbourne Cocoaheads June 2011
Epic Refactorings - Melbourne Cocoaheads June 2011Jesse Collis
 
CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012Jesse Collis
 
Xcode 4 shortcuts (Melbourne Cocoheads April 2011)
Xcode 4 shortcuts (Melbourne Cocoheads April 2011)Xcode 4 shortcuts (Melbourne Cocoheads April 2011)
Xcode 4 shortcuts (Melbourne Cocoheads April 2011)Jesse Collis
 
Integrating iAds (Melbourne Cocoaheads November 2010)
Integrating iAds (Melbourne Cocoaheads November 2010)Integrating iAds (Melbourne Cocoaheads November 2010)
Integrating iAds (Melbourne Cocoaheads November 2010)Jesse Collis
 

Mehr von Jesse Collis (6)

Preparing for iOS 9 - Melbourne Cocoaheads June 2015
Preparing for iOS 9 - Melbourne Cocoaheads June 2015Preparing for iOS 9 - Melbourne Cocoaheads June 2015
Preparing for iOS 9 - Melbourne Cocoaheads June 2015
 
A Brief History of Melbourne Cocoaheads - May 2013
A Brief History of Melbourne Cocoaheads - May 2013A Brief History of Melbourne Cocoaheads - May 2013
A Brief History of Melbourne Cocoaheads - May 2013
 
Epic Refactorings - Melbourne Cocoaheads June 2011
Epic Refactorings - Melbourne Cocoaheads June 2011Epic Refactorings - Melbourne Cocoaheads June 2011
Epic Refactorings - Melbourne Cocoaheads June 2011
 
CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012
 
Xcode 4 shortcuts (Melbourne Cocoheads April 2011)
Xcode 4 shortcuts (Melbourne Cocoheads April 2011)Xcode 4 shortcuts (Melbourne Cocoheads April 2011)
Xcode 4 shortcuts (Melbourne Cocoheads April 2011)
 
Integrating iAds (Melbourne Cocoaheads November 2010)
Integrating iAds (Melbourne Cocoaheads November 2010)Integrating iAds (Melbourne Cocoaheads November 2010)
Integrating iAds (Melbourne Cocoaheads November 2010)
 

Kürzlich hochgeladen

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Kürzlich hochgeladen (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Implementing CATiledLayer

  • 1. CATiledLayer Jesse Collis, Melbourne Cocoaheads, February 2012 jesse@jcmultimedia.com.au / @sirjec
  • 3. Tiled Views in 2009 Tiled UIScrollViews iOS 3 Compatibility @2x.png
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. My main goals • CATiledLayer in a zooming scrollView • Seamless integration into iOS4+ • Seamless integration between retina / non- retina screens • provide only one sized tile (not @2x)
  • 12. Here’s what I learnt • UIViews are backed by CALayers • All good CALayer documentation is OSX based • NSView is not backed by CALayer • drawRect: (more or less) equals drawLayer:inContext delegate method in OSX docs
  • 13. What I learnt cont... • Core Graphics helps with high resolution screens most of the time • CATiledLayer is just a CALayer subclass • It’s instantiated as a UIView’s layer • It uses drawRect: • contentScale is set by it’s UIView
  • 14. Basic Implementation +(Class)layerClass { return [CATiledLayer class]; } - (id)initWithFrame:(CGRect)frame { ... [(CATiledLayer *)self.layer setLevelsOfDetail:1]; [(CATiledLayer *)self.layer setLevelsOfDetailBias:3]; ... } - (void)drawRect:(CGRect)rect { CGContextRef c = UIGraphicsGetCurrentContext(); CGFloat scale = CGContextGetCTM(c).a; NSInteger col = (CGRectGetMinX(rect) * scale) / self.tileSize.width; NSInteger row = (CGRectGetMinY(rect) * scale) / self.tileSize.height; UIImage *tile_image = [self.tileSource tiledView:self imageForRow:row column:col scale:scale]; [tile_image drawInRect:rect]; }
  • 15. LOD & LODB • LOD is the number of levels it will ask you for as you zoom out • LODB is the number of levels it will use as you zoom in
  • 16. UIScrollView zoomScale vs. CATiledLayer LODB • zoomScale is measured on a linear scale • zoomScale has an exponential effect on pixels • Each LODB/LOD is a power of two more or less than the previous level of detail.
  • 17. UIScrollView zoomScale vs. CATiledLayer LODB • zoomScale is measured on a linear scale • zoomScale has an exponential effect on pixels • Each LODB/LOD is a power of two more or less than the previous level of detail.
  • 18. Some Notes • Setting LOD and LODB to 0 causes a blank view • Setting LOD and LODB to 1 seems to be undefined behaviour • Setting LOD to 1, and LODB > 1 is fine, but I like to set LOD to 0 if I’m using LODB.
  • 20. Retina Display Apple’s docs on Supporting High Resolution screens: [You] may need to adjust [Core Animation Layers] drawing code to account for scale factors. Normally, when you draw in your view’s drawRect: method … of the layer’s delegate, the system automatically adjusts the graphics context to account for scale factors. However, knowing or changing that scale factor might still be necessary when your view does one of the following: • Creates additional Core Animation layers with different scale factors and composites them into its own content.
  • 21. A few things you need to do • layer.contentsScale == 2 so everything in pixel land is squared • Multiply the original tileSize by the contentsScale • Multiply drawRect: rect by the context scale giving us our 512x512 tileSize • divide rect by contentsScale to give us rect with 256x256 dimensions • rect origin can now be used to grab the right tile • draw said tile it into rect; Core Graphics will do the rest
  • 22. What’s next • Add UIGestureRecognizer support for more map-like features • Overlay support • Replace UIImages with vectors or SVG drawing
  • 23. JCTiledView is on Github • github.com/jessedc/JCTiledScrollView

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n