How do I get the "real" frame of a prominent displayed scene in iPadOS 15?

iOS 15 adds a new way to display scenes which Apple seems to call "prominent" (docs). From what I can tell, your scene's window has a frame equal to the devices' main screen but then OS then scales it down for display. This is a problem because it seems that the keyboard's frame is not adjusted for this when listening to keyboard notifications via NotificationCenter which is making it impossible to implement keyboard avoidance for while the scene is displayed prominently. Has anyone else run into this or know of an API to get the actual dimensions of your scene so that it's possible to calculate?

Accepted Reply

UIWindowScene has its own coordinate space that you should be able to use for any kind of math that you need to do. iOS is not scaling anything, instead you should be getting a UIWindowScene in the correct size.

  • Thank you for the quick response! I think this is one of the first instances where I actually needed to use coordinate spaces instead of converting frames between views.

    For anyone else that finds this, after a bit of experimentation this worked best for me:

    CGRect keyboardRectInSelf = [self.view convertRect: keyboardRectInWindow fromCoordinateSpace: UIScreen.mainScreen.coordinateSpace];

Add a Comment

Replies

UIWindowScene has its own coordinate space that you should be able to use for any kind of math that you need to do. iOS is not scaling anything, instead you should be getting a UIWindowScene in the correct size.

  • Thank you for the quick response! I think this is one of the first instances where I actually needed to use coordinate spaces instead of converting frames between views.

    For anyone else that finds this, after a bit of experimentation this worked best for me:

    CGRect keyboardRectInSelf = [self.view convertRect: keyboardRectInWindow fromCoordinateSpace: UIScreen.mainScreen.coordinateSpace];

Add a Comment