Browse Source

Added checks to make sure that the current interface orientation is actually allowed when changing allowed interface orientations

tags/2021-05-28
hogliux 9 years ago
parent
commit
40994fcdab
1 changed files with 38 additions and 1 deletions
  1. +38
    -1
      modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm

+ 38
- 1
modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm View File

@@ -48,6 +48,20 @@ namespace Orientations
return Desktop::upright; return Desktop::upright;
} }
static UIInterfaceOrientation convertFromJuce (Desktop::DisplayOrientation orientation)
{
switch (orientation)
{
case Desktop::upright: return UIInterfaceOrientationPortrait;
case Desktop::upsideDown: return UIInterfaceOrientationPortraitUpsideDown;
case Desktop::rotatedClockwise: return UIInterfaceOrientationLandscapeLeft;
case Desktop::rotatedAntiClockwise: return UIInterfaceOrientationLandscapeRight;
default: jassertfalse; // unknown orientation!
}
return UIInterfaceOrientationPortrait;
}
static CGAffineTransform getCGTransformFor (const Desktop::DisplayOrientation orientation) noexcept static CGAffineTransform getCGTransformFor (const Desktop::DisplayOrientation orientation) noexcept
{ {
if (isUsingOldRotationMethod()) if (isUsingOldRotationMethod())
@@ -1029,7 +1043,30 @@ void Desktop::setKioskComponent (Component* kioskModeComp, bool enableOrDisable,
} }
} }
void Desktop::allowedOrientationsChanged() {}
void Desktop::allowedOrientationsChanged()
{
// if the current orientation isn't allowed anymore then switch orientations
if (! isOrientationEnabled (getCurrentOrientation()))
{
DisplayOrientation orientations[] = { upright, upsideDown, rotatedClockwise, rotatedAntiClockwise };
const int n = sizeof (orientations) / sizeof (DisplayOrientation);
int i;
for (i = 0; i < n; ++i)
if (isOrientationEnabled (orientations[i]))
break;
// you need to support at least one orientation
jassert (i < n);
i = jmin (n - 1, i);
NSNumber *value = [NSNumber numberWithInt:Orientations::convertFromJuce (orientations[i])];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
[value release];
}
}
//============================================================================== //==============================================================================
void UIViewComponentPeer::repaint (const Rectangle<int>& area) void UIViewComponentPeer::repaint (const Rectangle<int>& area)


Loading…
Cancel
Save