Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Retina Mac
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Weizhong Yang
August 26, 2012
Technology
3
220
Retina Mac
Weizhong Yang
August 26, 2012
Tweet
Share
More Decks by Weizhong Yang
See All by Weizhong Yang
導入 Flutter 前你應該知道的事
zonble
7
1.2k
那些年,被蘋果 Ban 掉的 API
zonble
0
110
為視障朋友打造行動應用
zonble
16
1.3k
Aspect Oriented Programming
zonble
2
220
Mac OS X 與 iOS 的 Audio API
zonble
11
970
大家來寫貪食蛇
zonble
7
4.4k
Debug Debug
zonble
6
390
HTML 5 Native Drag
zonble
3
510
Other Decks in Technology
See All in Technology
Data Intelligence on Lakehouse Paradigm
scotthsieh825
0
190
2026/01/16_実体験から学ぶ 2025年の失敗と対策_Progate Bar
teba_eleven
1
210
持続可能な開発のためのミニマリズム
sansantech
PRO
3
500
ファシリテーション勉強中 その場に何が求められるかを考えるようになるまで / 20260123 Naoki Takahashi
shift_evolve
PRO
2
190
新規事業 toitta におけるAI 機能評価の話 / AI Feature Evaluation in toitta
pokutuna
0
190
[Iceberg Meetup #4] ゼロからはじめる: Apache Icebergとはなにか? / Apache Iceberg for Beginners
databricksjapan
0
330
Web Intelligence and Visual Media Analytics
weblyzard
PRO
1
6.8k
迷わない!AI×MCP連携のリファレンスアーキテクチャ完全ガイド
cdataj
0
670
ReproでのicebergのStreaming Writeの検証と実運用にむけた取り組み
joker1007
0
370
人はいかにして 確率的な挙動を 受け入れていくのか
vaaaaanquish
4
2.1k
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
10k
書籍執筆での生成AIの活用
sat
PRO
1
160
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
800
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
72
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.7k
AI: The stuff that nobody shows you
jnunemaker
PRO
2
190
The Invisible Side of Design
smashingmag
302
51k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.5k
30 Presentation Tips
portentint
PRO
1
190
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
85
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
61
49k
Believing is Seeing
oripsolob
1
34
We Are The Robots
honzajavorek
0
140
Transcript
如何⽀支援 Mac OS X 的⾼高解析度模式 楊維中 a.k.a zonble
[email protected]
Sunday,
August 26,
萬惡的根源 Sunday, August 26,
開發環境 • MacBook Pro 2012 • 沒有新機器怎麼辦? • 使⽤用模擬環境 Sunday,
August 26,
模擬環境 Sunday, August 26,
模擬環境 Sunday, August 26,
模擬環境 Quartz Debug Sunday, August 26,
模擬環境 Sunday, August 26,
模擬環境 Sunday, August 26,
Sunday, August 26,
如何⽀支援? • 使⽤用兩倍圖檔 • 改⽤用向量圖形 Sunday, August 26,
使⽤用兩倍圖檔 • 跟 iOS ⼀一樣 • 所有⽤用到的圖⽚片 的檔名加上 @2x,然後加到 應⽤用程式中
Sunday, August 26,
使⽤用向量圖 • 向量圖檔格式很 多:Adobe Illustrator、 Corel Draw、 SVG… • Mac
OS X 系統 ⽀支援的向量格 式,簡單,就是 PDF Sunday, August 26,
Core Animation • CALayer 必須要⼿手動調整屬性,才有辦 法⽀支援 Retina Display • contents
直接給 @2x 圖⽚片是沒⽤用的 • 必須⼿手動設定 contentScale Sunday, August 26,
iOS 上⾯面 • aLayer. contentsScale = [UISCreen mainScreen].scale • 反正⼀一般來說,我們的
UI 只會出現在 mainScreen 上。雖然可以外接投影機, 使⽤用另外⼀一個 UIScreen,但是⼀一般不會 有⼈人去寫這種 App Sunday, August 26,
Mac OS X • CALayer 不⼀一定會出現在哪個 Screen 裡頭, ⽽而是要由⺫⽬目前 layer
所在的 Window 決定是否 要使⽤用⾼高解析度 • 詢問 NSWindow 的 -backingScaleFactor • Window 還可以在不同 Screen (主螢幕、延 伸螢幕)之間移動 • contentsScale 需要隨時改變 • 還有…向下相容,你應該不會只⽀支援 10.7.4 以上的系統 Sunday, August 26,
改變解析度的時機 • Layer 被放到某個 Window 的時候 • 因為 Window 移動⽽而造成
Window 的 scale 改變的時候(Notification) • 以下範例是假設 rootLayer 這個物件被擺 在某個 NSView 裡頭 Sunday, August 26,
Layer 被放到某個 Window 的時候 - (void)viewDidMoveToWindow { if ([rootLayer respondsToSelector:@selector(contentsScale)])
{ // 舊版的 OS 的 CALayer 不⼀一定會有 contentsScale // 舊版的 OS 的 Window 也不⼀一定會有 backingScaleFactor… CGFloat scale = [(id)[self window] backingScaleFactor]; [(id)rootLayer setContentsScale:scale]; } } Sunday, August 26,
訂閱 Window 移動⽽而 解析度改變的通知 • 訂閱 NSWindowDidChangeBackingPropertiesN otification • 但因為舊版系統沒有,所以直接訂閱字
串 @” NSWindowDidChangeBackingPropertiesN otification” Sunday, August 26,
訂閱 Window 移動⽽而 解析度改變的通知 • 在 viewDidMoveToWindow 訂閱 • 在
removeFromSuperview 取消 • 我們先來把剛剛那段修改 contentsScale 的程式拆出來 Sunday, August 26,
拆出來的 private method - (void)_updateContentScale { if (![self window]) {
return; } if ([rootLayer respondsToSelector:@selector(contentsScale)]) { CGFloat scale = [(id)[self window] backingScaleFactor]; [(id)rootLayer setContentsScale:scale]; } } Sunday, August 26,
訂閱通知 - (void)viewDidMoveToWindow { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scale DidChange:) name:@"NSWindowDidChangeBackingPropertiesNotification"
object:[self window]]; [self _updateContentScale]; } - (void)removeFromSuperview { [super removeFromSuperview]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)scaleDidChange:(NSNotification *)n { [self _updateContentScale]; } Sunday, August 26,
向下相容 • ⽤用舊版的 SDK 編譯,compiler 會跟你抱 怨沒有 contentsScale 與 backingScaleFactor…
很討厭 Sunday, August 26,
為了向下相容弄出來 的⻤⿁鬼 Category… @interface NSObject (RetinaDisplay) - (void)setContentsScale:(CGFloat)inScale; - (CGFloat)backingScaleFactor;
@end Sunday, August 26,
That’a all! Sunday, August 26,