Scrolling is backwards with external devices when rotating to landscape mode

We recently converted an existing app to adopt scenes (for CarPlay). The app has one main view controller that presents a WKWebView to show our content. Everything works fine in both landscape and portait mode when swiping on the screen to scroll. But with an iPad using an external Magic Keyboard, once you rotate to landscape mode the scrolling gestures are reversed. Swiping vertically on the trackpad is scrolling the page horizontally and vice versa. When this happens an error like below is logged (this error also shows up when in portait mode, but scrolling works as expected):

Unexpected window orientation: <UIWindow: 0x10370d8f0; orientation: landscapeLeft (4)> {
    hidden = NO;
    frame = {{0, 0}, {1180, 820}};
    bounds = {{0, 0}, {1180, 820}};
    ownsOrientation = NO;
    ownsOrientationTransform = NO;
    autorotationDisabled = NO;
    windowInterfaceOrientation = unknown (0);
    rootTransformOrientation = landscapeLeft (4);
    viewTransformOrientation = unknown (0);
    autorotationDisabled = NO;
    orientationVC = ... {
        providedSupportedOrientations = ( Pu Ll Lr Pd );
        resolvedSupportedOrientations = ( Pu Ll Lr Pd );
        canPreferOrientation = NO;
    };
}, event type: 6

It seems to suggest that while the view controller orientation is set correctly. It doesn't know what the orientation is for the window. I have been unable to figure out what would change with adopting scenes that would explain this behavior. I assume it has to do with the potential multi-window nature of it but haven't found any docs that describe how to ensure the window is setup to use the same orientation as the device. Any suggestions on things to check?

Answered by dheindel in 812930022

The issue seems to be that the window's frame was incorrectly tied to the old UIScreen.main.bounds value instead of the scene's windowScene.coordinateSpace.bounds. Changing that resolved the issue.

Accepted Answer

The issue seems to be that the window's frame was incorrectly tied to the old UIScreen.main.bounds value instead of the scene's windowScene.coordinateSpace.bounds. Changing that resolved the issue.

Scrolling is backwards with external devices when rotating to landscape mode
 
 
Q