AirPlay 與雙螢幕⽀支援
Johnny Sung
2013.10.17 @ CocoaHeads Taipei
Friday, October 18, 13
Friday, October 18, 13
Friday, October 18, 13
Apple TV
• Lightning Digital AV Adapter
• Lightning toVGA Adapter
• Apple 30-pin Digital AV Adapter
• Apple 30-pin toVGA A...
Friday, October 18, 13
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window...
剛剛在didFinishLaunchingWithOptions做了...
• ⽤用UIScreen的⼤大⼩小,來建⽴立 UIWindow
• 宣告⼀一個ViewController
• 指定rootViewController
• 讓此Win...
UIScreen
UIWindow
UIViewController
Friday, October 18, 13
螢幕數量變動的時機
⼿手機螢幕
⼿手機螢幕
第⼆二螢幕
第⼆二螢幕
didFinishLaunchingWithOptions
UIScreenDidConnectNotification
• APP執⾏行中,連接螢幕
• APP剛開啓時
Fr...
我們要做的
• APP啓動時
• 檢查⺫⽬目前螢幕的數量
註冊螢幕 連接/斷開 的notification
• 將對應的UIWindow設定好
• 收到螢幕連接的notification時
• 建⽴立對應的UIWindow並且設定
Friday, ...
NSArray* screens = [UIScreen screens];
for (UIScreen *screen in screens)
{
if (screen == [UIScreen mainScreen])
{
self.win...
註冊螢幕 連接/斷開 的notification (1/2)
在 application:didFinishLaunchingWithOptions: 裡
[[NSNotificationCenter defaultCenter] addObse...
註冊螢幕 連接/斷開 的notification (2/2)
- (void) screenDidConnect:(NSNotification *) notification
{
UIScreen* screen = [notification...
使⽤用雙螢幕之後
• 偵測第⼆二螢幕的解析度,並調整UI樣式
• 第⼆二螢幕的控制與溝通
Friday, October 18, 13
取得ViewController⺫⽬目前的解析度
在 viewDidLoad 裡
CGRect screenRect = [[[[self view] window] screen] bounds];
CGFloat screenWidth =...
Example:
https://github.com/j796160836/AirplayDemoTest
Ref.
• AirplayDemo
https://github.com/quellish/AirplayDemo
• Extern...
Reference
• Using Windows to Present Content on Multiple Displays
https://developer.apple.com/library/ios/documentation/Wi...
Q & A
Friday, October 18, 13
螢幕鏡射與否?
• 啓動雙螢幕(與⼿手機螢幕獨⽴立)
[self.window2 setScreen:screen];
self.window2.hidden=NO;
• 使⽤用鏡射(與⼿手機螢幕相同)
[self.window2 setScr...
將
self.viewController = [[ViewController alloc]
initWithNibName:@"ViewController" bundle:nil];
換成
UIStoryboard *mainStoryb...
腦筋急轉彎
試問
• [UIScreen mainScreen].bounds
• [UIApplcation sharedApplication].keyWindow.bounds
的差異?
http://stackoverflow.com/q...
Upcoming SlideShare
Loading in …5
×

[iOS] AirPlay 與雙螢幕支援

789 views

Published on

Published in: Technology, News & Politics
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
789
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
9
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

[iOS] AirPlay 與雙螢幕支援

  1. 1. AirPlay 與雙螢幕⽀支援 Johnny Sung 2013.10.17 @ CocoaHeads Taipei Friday, October 18, 13
  2. 2. Friday, October 18, 13
  3. 3. Friday, October 18, 13
  4. 4. Apple TV • Lightning Digital AV Adapter • Lightning toVGA Adapter • Apple 30-pin Digital AV Adapter • Apple 30-pin toVGA Adapter Friday, October 18, 13
  5. 5. Friday, October 18, 13
  6. 6. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; } 這是我們常常在AppDelegate看到的句⼦子 Friday, October 18, 13
  7. 7. 剛剛在didFinishLaunchingWithOptions做了... • ⽤用UIScreen的⼤大⼩小,來建⽴立 UIWindow • 宣告⼀一個ViewController • 指定rootViewController • 讓此Window提到最前,並且可被看⾒見 Friday, October 18, 13
  8. 8. UIScreen UIWindow UIViewController Friday, October 18, 13
  9. 9. 螢幕數量變動的時機 ⼿手機螢幕 ⼿手機螢幕 第⼆二螢幕 第⼆二螢幕 didFinishLaunchingWithOptions UIScreenDidConnectNotification • APP執⾏行中,連接螢幕 • APP剛開啓時 Friday, October 18, 13
  10. 10. 我們要做的 • APP啓動時 • 檢查⺫⽬目前螢幕的數量 註冊螢幕 連接/斷開 的notification • 將對應的UIWindow設定好 • 收到螢幕連接的notification時 • 建⽴立對應的UIWindow並且設定 Friday, October 18, 13
  11. 11. NSArray* screens = [UIScreen screens]; for (UIScreen *screen in screens) { if (screen == [UIScreen mainScreen]) { self.window = [[UIWindow alloc] initWithFrame:[screen bounds]]; [self.window setScreen:screen]; ViewControllerA* vcA=[ViewControllerA alloc] initWithNibName:@"xibA" bundle:nil]; self.window.rootViewController = vcA; [self.window makeKeyAndVisible]; } else { self.window2 = [[UIWindow alloc] initWithFrame:[screen bounds]]; [self.window2 setScreen:screen]; ViewControllerB* vcB=[ViewControllerB alloc] initWithNibName:@"xibB" bundle:nil]; self.window2.rootViewController = vcB; self.window2.hidden=NO; } } 根據UIScreen設定對應的UIWindow Friday, October 18, 13
  12. 12. 註冊螢幕 連接/斷開 的notification (1/2) 在 application:didFinishLaunchingWithOptions: 裡 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil]; APP關閉時,記得解除註冊 在 applicationWillTerminate: 裡 [[NSNotificationCenter defaultCenter] removeObserver:self name:UIScreenDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIScreenDidDisconnectNotification object:nil]; Friday, October 18, 13
  13. 13. 註冊螢幕 連接/斷開 的notification (2/2) - (void) screenDidConnect:(NSNotification *) notification { UIScreen* screen = [notification object]; // 建⽴立UIWindow ... } Friday, October 18, 13
  14. 14. 使⽤用雙螢幕之後 • 偵測第⼆二螢幕的解析度,並調整UI樣式 • 第⼆二螢幕的控制與溝通 Friday, October 18, 13
  15. 15. 取得ViewController⺫⽬目前的解析度 在 viewDidLoad 裡 CGRect screenRect = [[[[self view] window] screen] bounds]; CGFloat screenWidth = screenRect.size.width; CGFloat screenHeight = screenRect.size.height; NSLog(@"Screen: %.0f x %.0f", screenWidth, screenHeight); Friday, October 18, 13
  16. 16. Example: https://github.com/j796160836/AirplayDemoTest Ref. • AirplayDemo https://github.com/quellish/AirplayDemo • ExternalDisplay https://developer.apple.com/library/ios/samplecode/ExternalDisplay/Introduction/Intro.html Friday, October 18, 13
  17. 17. Reference • Using Windows to Present Content on Multiple Displays https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/WindowAndScreenGuide/ Introduction/Introduction.html • Understanding Windows and Screens https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/WindowAndScreenGuide/ WindowScreenRolesinApp/WindowScreenRolesinApp.html • Presenting Content on an External Display https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/WindowAndScreenGuide/ UsingExternalDisplay/UsingExternalDisplay.html#//apple_ref/doc/uid/TP40012555-CH3-SW1 • UIScreen Class Reference https://developer.apple.com/library/ios/documentation/uikit/reference/UIScreen_Class/Reference/UIScreen.html • UIWindow Class Reference https://developer.apple.com/library/ios/documentation/uikit/reference/UIWindow_Class/ UIWindowClassReference/UIWindowClassReference.html Friday, October 18, 13
  18. 18. Q & A Friday, October 18, 13
  19. 19. 螢幕鏡射與否? • 啓動雙螢幕(與⼿手機螢幕獨⽴立) [self.window2 setScreen:screen]; self.window2.hidden=NO; • 使⽤用鏡射(與⼿手機螢幕相同) [self.window2 setScreen:nil]; self.window2.hidden=YES; Friday, October 18, 13
  20. 20. 將 self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 換成 UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; self.viewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"ViewController"]; 使⽤用 StoryBoard ? Friday, October 18, 13
  21. 21. 腦筋急轉彎 試問 • [UIScreen mainScreen].bounds • [UIApplcation sharedApplication].keyWindow.bounds 的差異? http://stackoverflow.com/questions/17465547/uiscreen-mainscreen-bounds-vs-uiapplcation-sharedapplication-keywindow-bound Friday, October 18, 13

×