Skip to content

Commit e8c8ef0

Browse files
authored
Merge pull request #629 from huven/visionos-orientation
Fixes initial orientation issue on visionOS
2 parents be29621 + 220b467 commit e8c8ef0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Objective-C/TOCropViewController/TOCropViewController.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,18 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIVi
595595
// If the size doesn't change (e.g, we did a 180 degree device rotation), don't bother doing a relayout
596596
if (CGSizeEqualToSize(size, self.view.bounds.size)) { return; }
597597

598+
#if !TARGET_OS_VISION
598599
UIInterfaceOrientation orientation = UIInterfaceOrientationPortrait;
599600
CGSize currentSize = self.view.bounds.size;
600601
if (currentSize.width < size.width) {
601602
orientation = UIInterfaceOrientationLandscapeLeft;
602603
}
603-
604+
#else
605+
// On visionOS, this method is called on presentation with size=(0,0),
606+
// which would set orientation incorrectly causing views to be misplaced.
607+
UIInterfaceOrientation orientation = UIInterfaceOrientationLandscapeLeft;
608+
#endif
609+
604610
[self _willRotateToInterfaceOrientation:orientation duration:coordinator.transitionDuration];
605611
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
606612
[self _willAnimateRotationToInterfaceOrientation:orientation duration:coordinator.transitionDuration];

0 commit comments

Comments
 (0)