Как заставить iOS отображать экран с разрешением внешнего дисплея как на iPhone, так и на внешнем дисплее?IOS

Программируем под IOS
Anonymous
Как заставить iOS отображать экран с разрешением внешнего дисплея как на iPhone, так и на внешнем дисплее?

Сообщение Anonymous »

У меня возникла проблема: «ExternalDesktopView» отображается с разрешением iPhone в полноэкранном режиме и на телевизоре. Например, это выглядит как обычное зеркальное отображение iPhone в виде огромной черной дыры вверх и вниз.
За это отвечает функция setupExternalWindow.
ExternalDisplayManager.swift:
private func setupExternalWindow(for screen: UIScreen) {
removeExternalWindow()

guard let mode = screen.currentMode else {
print("⚠️ No screen mode found for external display.")
return
}

let nativeSize = mode.size
let scale = screen.nativeScale
let logicalSize = CGSize(width: nativeSize.width / scale,
height: nativeSize.height / scale)

print("""
🖥️ External Display Info:
- Native pixel size: \(nativeSize)
- Logical size: \(logicalSize)
- Scale: \(scale)
""")

let window = UIWindow(frame: screen.coordinateSpace.bounds)
window.screen = screen
window.backgroundColor = .black
window.isHidden = true
window.contentScaleFactor = scale

let desktop = DesktopModelHolder.shared.desktopModel
let cursor = CursorManager.shared

let externalRoot = ExternalDesktopView()
.environmentObject(desktop)
.environmentObject(cursor)
.ignoresSafeArea()
.frame(width: logicalSize.width, height: logicalSize.height)
.clipped()

let host = UIHostingController(rootView: AnyView(externalRoot))
host.view.backgroundColor = .black
host.view.frame = window.bounds
host.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
host.view.contentScaleFactor = scale
host.view.layer.contentsScale = scale
host.view.transform = .identity

host.additionalSafeAreaInsets = .zero
host.view.layer.masksToBounds = true
host.modalPresentationStyle = .fullScreen

window.rootViewController = host

DispatchQueue.main.async {
self.externalWindow = window
self.externalHostingController = host
window.isHidden = false
window.makeKeyAndVisible()
host.view.layoutIfNeeded()
CATransaction.flush()
self.isExternalConnected = true

print("External display is now rendered in TRUE FULLSCREEN.")
}

updateExternalPointer(from: cursor.mainPointerLocation)
}


Подробнее здесь: https://stackoverflow.com/questions/798 ... both-iphon

Вернуться в «IOS»