ondalabs/OLGhostAlertView

Adding an OLGhostAlertView while displaying a keyboard will cause it to be placed under the keyboard

radutzan opened this issue · 7 comments

Since we can only receive notifications for keyboards if they are fired after we init an OLGhostAlertView, we can't know if there's one being displayed before instantiating the view, and therefore we cannot adjust the frame accordingly, causing the view to be placed under the keyboard in the view hierarchy.

There's really no way that we know of to fix this. Adding the view as a subview of the key window (#1) does allow for the view to be drawn on top of the keyboard, but this is not acceptable behaviour.

Well, this could be amended by using some keyboard listener that always receives these notifications from the beginning of the app's life cycle. Being a singleton (dispatch_once) you could query it for the status and keyboard height.

There are some examples of this, and I can give you one if needed.

This sounds great, it'd be awesome if you could give me some examples. Doing this would also fix #2.

Something like in my gist here: https://gist.github.com/3845949

You'd call it once in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
using [LWSKeyboardListener defaultListener]; to register for the notifications.

And in any other class you might want to know about the current state of the keyboard, just inlcude LWSKeyboardListener.h and get the properties of the shared instance (keyboardShowed, keyboardRect, keyboardHeight).

For example in OLGhostAlertview.m in the - (void)show method, add bottomMargin += [LWSKeyboardListener defaultListener].keyboardHeight; to account for the keyboard height.

I added keyboardHeight, because the keyboardRect doesn't care for the interface orientation and always has coordinates as if the device were upright, home button on the bottom. Therefore I simply return the minimum of width and height of the rect.

This looks like a nice solution, but I wanna keep OLGAV as simple as possible. I'll mention your comment on the README for people who need this fixed. Thanks a lot!

Yes, I understand completely. It's quite unfortunate that there is no public API for this.

This can also be worked around using the position property.

Hi,
You can check my solution with the alert placement here #24.
In this solution the OLGhostAlertView:

  • doesn't need to be shown in or after viewDidAppear,
  • is always visible above the keyboard.