Skip to content

Commit

Permalink
Fix view frame in portrait when starting iOS app in landscape
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHills committed Sep 11, 2020
1 parent e475499 commit 0793ac0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- **Breaking:** `primary_monitor` now returns `Option<MonitorHandle>`.
- On macOS, updated core-* dependencies and cocoa.
- Bump `parking_lot` to 0.11
- On iOS, fixed starting the app in landscape where the view still had portrait dimensions.

# 0.22.2 (2020-05-16)

Expand Down
12 changes: 12 additions & 0 deletions src/platform_impl/ios/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class {
height: screen_frame.size.height as f64,
}
.to_physical(scale_factor.into());

// If the app is started in landscape, the view frame and window bounds can be mismatched.
// The view frame will be in portrait and the window bounds in landscape. So apply the
// window bounds to the view frame to make it consistent.
let view_frame: CGRect = msg_send![object, frame];
let window_bounds: CGRect = msg_send![window, bounds];
if view_frame.size.width != window_bounds.size.width
|| view_frame.size.height != window_bounds.size.height
{
let () = msg_send!(object, setFrame: window_bounds);
}

app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.into()),
event: WindowEvent::Resized(size),
Expand Down

0 comments on commit 0793ac0

Please sign in to comment.