【swift】 iPhone에서 외부 디스플레이에 View를 표시 【iOS】
그것이 가능합니다!
그래, iPhone이야.
절차
공식적으로 완결에 모였습니다.
외부 디스플레이를 연결했을 때 알림을 받고,
또한 거기에서 연결된 UIScreen을 얻을 수 있으므로 해당 UIScreen의 정보를 기반으로UIWindow 를 만들고 그 UIWindow 의 view 에 좋아하는 View 를 얹는 것만 큼 간단합니다.
Displaying Content on a Connected Screen | Apple Developer Documentation
htps : //로 ゔぇぺぺr. 아 ぇ. 코 m / 도쿠 멘 타치 온 / 우이 키 t / 우 엔도 ws_ an d_ sc 렌 s / ぢ sp ぁ y 엔 g_ 콘텐 t_ 온_ 아_ 콘 d d sc 렌
실행 결과
이번에는 WKWebView를 외부 디스플레이에 표시해 보았습니다.
각 사이트의 버튼을 누르면 해당 사이트를 외부 디스플레이에 표시하는 간단한 샘플입니다.

참고로 외부 디스플레이는 simulator의 다음 메뉴에서 볼 수 있습니다.
Hardware > External Display

코드
그렇게 많은 절차가 아니기 때문에,
코드 전부 타고 있습니다.
setupNotificationCenter()에서 외부 디스플레이가 연결되었을 때와 연결이 끊어졌을 때 알림을 등록합니다.
ViewController.swiftimport UIKit
import WebKit
class ViewController: UIViewController {
private let webView = WKWebView()
private var externalWindow : UIWindow?
override func viewDidLoad() {
super.viewDidLoad()
setupNotificationCenter()
}
private func setupNotificationCenter() {
NotificationCenter.default.addObserver(
self,
selector: #selector(addExternalDisplay(notification:)),
name: UIScreen.didConnectNotification,
object: nil
)
NotificationCenter.default.addObserver(
self,
selector: #selector(removeExternalDisplay(notification:)),
name: UIScreen.didDisconnectNotification,
object: nil
)
}
@objc func addExternalDisplay(notification : Notification) {
guard let newScreen = notification.object as? UIScreen else {
return
}
let screenDimensions = newScreen.bounds
let newWindow = UIWindow(frame: screenDimensions)
newWindow.screen = newScreen
webView.frame = newWindow.frame
newWindow.addSubview(webView)
newWindow.isHidden = false
// window を破棄させないため プロパティに保持
externalWindow = newWindow
}
@objc func removeExternalDisplay(notification : Notification) {
externalWindow = nil
}
@IBAction func didTapButton0(_ sender: Any) {
load(urlString: "https://www.google.com")
}
@IBAction func didTapButton1(_ sender: Any) {
load(urlString: "https://www.yahoo.co.jp")
}
@IBAction func didTapButton2(_ sender: Any) {
load(urlString: "https://www.apple.com/jp")
}
private func load(urlString : String) {
guard let url = URL(string: urlString) else {
return
}
let urlRequest = URLRequest(url: url)
webView.load(urlRequest)
}
}
실제 기계 동작
Lightning → HDMI 변환 어댑터가 필요합니다.
비정규 버전도 시도했지만 화면 미러링 표시는 가능하지만
외부 디스플레이 감지가 불가능한 것 같습니다.
그래서, 순조롭게 순정품을 사용합시다. (비싸지 만 ...
Amazon | Apple Lightning - Digital AV 어댑터 | 커넥터 및 변환 케이블 통신 판매
htps : // 아 mz 응. 및 / 2jWLCwz
실기 동작의 모습

디버깅 방법
HDMI 변환 케이블에 Lightning의 케이블 접속구는 있습니다만,
여기에서 mac에 연결해도 단말 인식을 해주지 않는 것 같습니다.
그 때문에, 디버그 접속을 할 수 없고 곤란하다고 생각합니다.
그러나 Xcode에는 무선 디버깅 기능이 있으며 iPhone을 mac에 연결하지 않아도
디버깅이 가능하므로, 디버깅을 하고 싶을 때는 이 절차를 취합시다.
Xcode 9 & iOS 11에서 가능한 무선 디버깅 절차
htps : // 이 m/바시/있어 ms/2에3후아928d6018f312b7
github
github에 프로젝트를 통째로 올리고 있습니다.
htps : // 기주 b. 이 m / becky 3 / e x r r l_a sp y y st
Reference
이 문제에 관하여(【swift】 iPhone에서 외부 디스플레이에 View를 표시 【iOS】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/beckyJPN/items/c002dc7aaac0295a30ba
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
이번에는
WKWebView를 외부 디스플레이에 표시해 보았습니다.각 사이트의 버튼을 누르면 해당 사이트를 외부 디스플레이에 표시하는 간단한 샘플입니다.

참고로 외부 디스플레이는 simulator의 다음 메뉴에서 볼 수 있습니다.
Hardware > External Display
코드
그렇게 많은 절차가 아니기 때문에,
코드 전부 타고 있습니다.
setupNotificationCenter()에서 외부 디스플레이가 연결되었을 때와 연결이 끊어졌을 때 알림을 등록합니다.
ViewController.swiftimport UIKit
import WebKit
class ViewController: UIViewController {
private let webView = WKWebView()
private var externalWindow : UIWindow?
override func viewDidLoad() {
super.viewDidLoad()
setupNotificationCenter()
}
private func setupNotificationCenter() {
NotificationCenter.default.addObserver(
self,
selector: #selector(addExternalDisplay(notification:)),
name: UIScreen.didConnectNotification,
object: nil
)
NotificationCenter.default.addObserver(
self,
selector: #selector(removeExternalDisplay(notification:)),
name: UIScreen.didDisconnectNotification,
object: nil
)
}
@objc func addExternalDisplay(notification : Notification) {
guard let newScreen = notification.object as? UIScreen else {
return
}
let screenDimensions = newScreen.bounds
let newWindow = UIWindow(frame: screenDimensions)
newWindow.screen = newScreen
webView.frame = newWindow.frame
newWindow.addSubview(webView)
newWindow.isHidden = false
// window を破棄させないため プロパティに保持
externalWindow = newWindow
}
@objc func removeExternalDisplay(notification : Notification) {
externalWindow = nil
}
@IBAction func didTapButton0(_ sender: Any) {
load(urlString: "https://www.google.com")
}
@IBAction func didTapButton1(_ sender: Any) {
load(urlString: "https://www.yahoo.co.jp")
}
@IBAction func didTapButton2(_ sender: Any) {
load(urlString: "https://www.apple.com/jp")
}
private func load(urlString : String) {
guard let url = URL(string: urlString) else {
return
}
let urlRequest = URLRequest(url: url)
webView.load(urlRequest)
}
}
실제 기계 동작
Lightning → HDMI 변환 어댑터가 필요합니다.
비정규 버전도 시도했지만 화면 미러링 표시는 가능하지만
외부 디스플레이 감지가 불가능한 것 같습니다.
그래서, 순조롭게 순정품을 사용합시다. (비싸지 만 ...
Amazon | Apple Lightning - Digital AV 어댑터 | 커넥터 및 변환 케이블 통신 판매
htps : // 아 mz 응. 및 / 2jWLCwz
실기 동작의 모습

디버깅 방법
HDMI 변환 케이블에 Lightning의 케이블 접속구는 있습니다만,
여기에서 mac에 연결해도 단말 인식을 해주지 않는 것 같습니다.
그 때문에, 디버그 접속을 할 수 없고 곤란하다고 생각합니다.
그러나 Xcode에는 무선 디버깅 기능이 있으며 iPhone을 mac에 연결하지 않아도
디버깅이 가능하므로, 디버깅을 하고 싶을 때는 이 절차를 취합시다.
Xcode 9 & iOS 11에서 가능한 무선 디버깅 절차
htps : // 이 m/바시/있어 ms/2에3후아928d6018f312b7
github
github에 프로젝트를 통째로 올리고 있습니다.
htps : // 기주 b. 이 m / becky 3 / e x r r l_a sp y y st
Reference
이 문제에 관하여(【swift】 iPhone에서 외부 디스플레이에 View를 표시 【iOS】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/beckyJPN/items/c002dc7aaac0295a30ba
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
import UIKit
import WebKit
class ViewController: UIViewController {
private let webView = WKWebView()
private var externalWindow : UIWindow?
override func viewDidLoad() {
super.viewDidLoad()
setupNotificationCenter()
}
private func setupNotificationCenter() {
NotificationCenter.default.addObserver(
self,
selector: #selector(addExternalDisplay(notification:)),
name: UIScreen.didConnectNotification,
object: nil
)
NotificationCenter.default.addObserver(
self,
selector: #selector(removeExternalDisplay(notification:)),
name: UIScreen.didDisconnectNotification,
object: nil
)
}
@objc func addExternalDisplay(notification : Notification) {
guard let newScreen = notification.object as? UIScreen else {
return
}
let screenDimensions = newScreen.bounds
let newWindow = UIWindow(frame: screenDimensions)
newWindow.screen = newScreen
webView.frame = newWindow.frame
newWindow.addSubview(webView)
newWindow.isHidden = false
// window を破棄させないため プロパティに保持
externalWindow = newWindow
}
@objc func removeExternalDisplay(notification : Notification) {
externalWindow = nil
}
@IBAction func didTapButton0(_ sender: Any) {
load(urlString: "https://www.google.com")
}
@IBAction func didTapButton1(_ sender: Any) {
load(urlString: "https://www.yahoo.co.jp")
}
@IBAction func didTapButton2(_ sender: Any) {
load(urlString: "https://www.apple.com/jp")
}
private func load(urlString : String) {
guard let url = URL(string: urlString) else {
return
}
let urlRequest = URLRequest(url: url)
webView.load(urlRequest)
}
}
Lightning → HDMI 변환 어댑터가 필요합니다.
비정규 버전도 시도했지만 화면 미러링 표시는 가능하지만
외부 디스플레이 감지가 불가능한 것 같습니다.
그래서, 순조롭게 순정품을 사용합시다. (비싸지 만 ...
Amazon | Apple Lightning - Digital AV 어댑터 | 커넥터 및 변환 케이블 통신 판매
htps : // 아 mz 응. 및 / 2jWLCwz
실기 동작의 모습

디버깅 방법
HDMI 변환 케이블에 Lightning의 케이블 접속구는 있습니다만,
여기에서 mac에 연결해도 단말 인식을 해주지 않는 것 같습니다.
그 때문에, 디버그 접속을 할 수 없고 곤란하다고 생각합니다.
그러나 Xcode에는 무선 디버깅 기능이 있으며 iPhone을 mac에 연결하지 않아도
디버깅이 가능하므로, 디버깅을 하고 싶을 때는 이 절차를 취합시다.
Xcode 9 & iOS 11에서 가능한 무선 디버깅 절차
htps : // 이 m/바시/있어 ms/2에3후아928d6018f312b7
github
github에 프로젝트를 통째로 올리고 있습니다.
htps : // 기주 b. 이 m / becky 3 / e x r r l_a sp y y st
Reference
이 문제에 관하여(【swift】 iPhone에서 외부 디스플레이에 View를 표시 【iOS】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/beckyJPN/items/c002dc7aaac0295a30ba
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
github에 프로젝트를 통째로 올리고 있습니다.
htps : // 기주 b. 이 m / becky 3 / e x r r l_a sp y y st
Reference
이 문제에 관하여(【swift】 iPhone에서 외부 디스플레이에 View를 표시 【iOS】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/beckyJPN/items/c002dc7aaac0295a30ba텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)