ALAlertBanner icon indicating copy to clipboard operation
ALAlertBanner copied to clipboard

Listen for UIApplicationDidChangeStatusBarOrientationNotification instead of UIDeviceOrientationDidChangeNotification

Open lobianco opened this issue 10 years ago • 4 comments

ALAlertBanner listens for UIDeviceOrientationDidChangeNotification to handle rotation events. I'd prefer to listen for UIApplicationDidChangeStatusBarOrientationNotification instead but I need the bounds of the banner's superview to update before handling the rotation notification, and the only way to that seems to be by using UIDeviceOrientationDidChangeNotification.

lobianco avatar Sep 02 '13 22:09 lobianco

You could use KVO to observe the superview's frame and layout whenever it changes...

ryanpeggs avatar Sep 07 '13 21:09 ryanpeggs

Good suggestion. I'll give it a shot. Thanks!

lobianco avatar Sep 08 '13 00:09 lobianco

@ryanpeggs, take a look at this commit: e15cfacfc75981794afb66deef0cc7de2e0ede5d

I switched over to KVO but there's a problem with monitoring the view's frame. Because the navigation bar resizes itself when going between landscape and portrait, it causes observeValueForKeyPath: to fire multiple times, which messes up the banner if it's in the middle of an animation (doesn't really "mess it up" but basically just makes it snap to it's final location without animating the rest of the transition). I don't know if it's going to be feasible to use KVO unless i can refactor the code to deal with this issue.

lobianco avatar Sep 10 '13 15:09 lobianco

And this post on StackOverflow makes me think it's best to not use KVO at all...

I suppose I could always add a frame-changed-notifier method to put in the view controller's willAnimateRotationToInterfaceOrientation: and make it mandatory to implement or something like that... but that feels like it's getting messy.

lobianco avatar Sep 10 '13 15:09 lobianco