diff --git a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm index 5e6508e56b..86b5616aeb 100644 --- a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm @@ -101,6 +101,23 @@ namespace Orientations } } +struct AsyncBoundsUpdater : public AsyncUpdater +{ + AsyncBoundsUpdater (UIViewController* vc) + : viewController (vc) + { + } + + ~AsyncBoundsUpdater() override + { + cancelPendingUpdate(); + } + + void handleAsyncUpdate() override; + + UIViewController* viewController; +}; + //============================================================================== } // namespace juce @@ -134,8 +151,12 @@ using namespace juce; //============================================================================== @interface JuceUIViewController : UIViewController { +@public + std::unique_ptr boundsUpdater; } +- (JuceUIViewController*) init; + - (NSUInteger) supportedInterfaceOrientations; - (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation; - (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation duration: (NSTimeInterval) duration; @@ -342,6 +363,11 @@ static void sendScreenBoundsUpdate (JuceUIViewController* c) juceView->owner->updateTransformAndScreenBounds(); } +void AsyncBoundsUpdater::handleAsyncUpdate() +{ + sendScreenBoundsUpdate ((JuceUIViewController*) viewController); +} + static bool isKioskModeView (JuceUIViewController* c) { JuceUIView* juceView = (JuceUIView*) [c view]; @@ -358,6 +384,15 @@ MultiTouchMapper UIViewComponentPeer::currentTouches; //============================================================================== @implementation JuceUIViewController +- (JuceUIViewController*) init +{ + self = [super init]; + + boundsUpdater = std::make_unique (self); + + return self; +} + - (NSUInteger) supportedInterfaceOrientations { return Orientations::getSupportedOrientations(); @@ -390,7 +425,8 @@ MultiTouchMapper UIViewComponentPeer::currentTouches; // On some devices the screen-size isn't yet updated at this point, so also trigger another // async update to double-check.. - MessageManager::callAsync ([=] { sendScreenBoundsUpdate (self); }); + if (boundsUpdater != nullptr) + boundsUpdater->triggerAsyncUpdate(); } - (BOOL) prefersStatusBarHidden @@ -629,6 +665,8 @@ UIViewComponentPeer::~UIViewComponentPeer() currentTouches.deleteAllTouchesForPeer (this); Desktop::getInstance().removeFocusChangeListener (this); + ((JuceUIViewController*) controller)->boundsUpdater = nullptr; + view->owner = nullptr; [view removeFromSuperview]; [view release];