This is a migrated thread and some comments may be shown as answers.

TKAlert hidden behind keyboard

3 Answers 49 Views
Alert
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ryan
Top achievements
Rank 1
Ryan asked on 27 Feb 2017, 07:09 PM
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

3 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 02 Mar 2017, 06:01 PM
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.
0
Ryan
Top achievements
Rank 1
answered on 02 Mar 2017, 06:54 PM
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.
0
Todor
Telerik team
answered on 07 Mar 2017, 09:30 AM
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.
Tags
Alert
Asked by
Ryan
Top achievements
Rank 1
Answers by
Todor
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or