Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

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

Open
radutzan opened this issue Aug 22, 2012 · 7 comments

Comments

@radutzan
Copy link
Member

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.

@leberwurstsaft
Copy link

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.

@radutzan
Copy link
Member Author

radutzan commented Oct 5, 2012

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

@leberwurstsaft
Copy link

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.

@radutzan
Copy link
Member Author

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!

@leberwurstsaft
Copy link

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

@crowl crowl closed this as completed Nov 26, 2012
@crowl crowl reopened this Nov 26, 2012
@radutzan
Copy link
Member Author

This can also be worked around using the position property.

@pmkowal
Copy link

pmkowal commented Aug 21, 2014

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants