TKAlert hidden behind keyboard

Thread is closed for posting
4 posts, 0 answers
  1. Ryan
    Ryan avatar
    37 posts
    Member since:
    Jun 2016

    Posted 27 Feb Link to this post

    Is there a way to have the TKAlert move above the keyboard like UIAlertController does by default? I have a TKAutoCompletTextView inside my TKAlert contentView and part of the alert is hidden behind the keyboard when I try to type in the TKAutoCompleteTextView
  2. Todor
    Admin
    Todor avatar
    798 posts

    Posted 02 Mar Link to this post

    Hi Ryan,

    You can use the register for keyboard notifications as explained here and adjust the alert and its content view accordingly. If you really want the alert placed on top of the keyboard (even though it sounds a little strange to hide the keyboard while the user is expected to type) you can use the UIWindow's bringSubviewToFront:

    - (void)keyboardWillShow:(NSNotification*)aNotification
    {
        UIWindow *window = [UIApplication sharedApplication].windows.lastObject;
        [window addSubview:alert.alertView];
        [window bringSubviewToFront:alert.alertView];
    }

    Given that you have the following code in your view controller:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

    I hope this information helps.

    Regards,
    Todor
    Telerik by Progress
    Want to build beautiful Android apps as well? Check out UI for Android which enables the same set of scenarios, allowing you to create the same great app experience on both iOS and Android.
  3. Ryan
    Ryan avatar
    37 posts
    Member since:
    Jun 2016

    Posted 02 Mar in reply to Todor Link to this post

    I want the alert to move up on the screen when the keyboard shows so that the keyboard is not on top of the alert hiding the alert. UIAlertController and UIAlertView automatically move up on the screen so that it is not covered by the keyboard. I think this is something the TKAlert should have by default.
  4. Todor
    Admin
    Todor avatar
    798 posts

    Posted 07 Mar Link to this post

    Hello Ryan,

    Thank you for getting back to us.

    Please accept my apologies for the misunderstanding in my previous post. I have logged your suggestion for improvement in our feedback portal. For now you can move the alert manually when the keyboard shows. One way to do it is by registering for keyboardWillShow (as mentioned in the previous post) and keyboardWillBeHidden and moving the alert with appropriate values:

    - (void)keyboardWillShow:(NSNotification*)aNotification
    {
        NSDictionary* info = [aNotification userInfo];
        CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
        CGRect backgroundRect = alert.alertView.superview.frame;
        CGFloat availableHeight = backgroundRect.size.height - keyboardSize.height;
        CGFloat alertBottom = alert.alertView.frame.origin.y + alert.alertView.frame.size.height;
        originalFrame = alert.alertView.frame;
        if(alertBottom > availableHeight) {
            CGFloat diff = alertBottom - availableHeight;
            alert.alertView.frame = CGRectMake(alert.alertView.frame.origin.x, alert.alertView.frame.origin.y - diff, alert.alertView.frame.size.width, alert.alertView.frame.size.height);
        }
    }
     
    - (void)keyboardWillBeHidden:(NSNotification*)aNotification
    {
        alert.alertView.frame = originalFrame;
    }

    I hope this information helps. I have updated your Telerik points for your valuable feedback.

    Regards,
    Todor
    Telerik by Progress
    Want to build beautiful Android apps as well? Check out UI for Android which enables the same set of scenarios, allowing you to create the same great app experience on both iOS and Android.
Back to Top