Kaz Miller
Kaz Miller

Reputation: 979

Content displayed on a connected screen is not showed in full screen in Swift

When testing my app in a real device connected to a tv or monitor by hdmi cable, the content that is showed in the connected screen is not showed in full screen.

In a real device with a real connected screen: enter image description here

I have tested my app in the iOS Simulator with the simulated connected screen and everything works great.

In the iOS Simulator: enter image description here

I have tested my app in different kinds of screens and the content in the connected screen is never showed in full screen when using real devices.

I have also tested this example having the same results.

This is part of the code:

if UIScreen.screens.count > 1 {
    let secondScreen = UIScreen.screens[1]
    secondWindow = UIWindow(frame: secondScreen.bounds)
    secondWindow.rootViewController = UIViewController()
    secondWindow.screen = secondScreen

    let secondScreenView = UIView(frame: secondWindow.frame)
    secondWindow.addSubview(secondScreenView)
    secondWindow.isHidden = false

    secondScreenView.backgroundColor = .purple

    let imageView = UIImageView(frame: secondScreenView.bounds)
    imageView.image = UIImage(data: recursoTipoRecurso.recurso.contenido as Data)
    imageView.contentMode = .scaleToFill

    secondScreenView.addSubview(imageView)
}

As showed in the previous images there is a space between the monitor screen border and the content I set.

What am I doing wrong?

Upvotes: 5

Views: 1042

Answers (2)

Creanomy
Creanomy

Reputation: 226

Set your second screen with overscanCompensation to .none will certainly help. It did for me.

let secondScreen = UIScreen.screens[1]
secondScreen.overscanCompensation = .none

Apple Dev Definition

Upvotes: 1

MarcoCarnevali
MarcoCarnevali

Reputation: 668

It's not an issue with the app/code, it's an issue of the screen ratio. While connecting it to the external screen the monitor keep the iPad screen ratio. The only way is to manually change the size of the content on the monitor itself by stretching it. Hope it helps!

Upvotes: 0

Related Questions