resize view when keyboard appears

This commit is contained in:
2017-07-29 15:02:27 +01:00
parent b0d28f3a6c
commit d01ec65cad
3 changed files with 39 additions and 2 deletions

View File

@@ -43,6 +43,42 @@ int t_count = 0;
return YES;
}
// Call this method somewhere in your view controller setup code.
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
}
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
GLKView *view = (GLKView *)self.view;
CGRect frame = view.frame;
frame.size.height -= kbSize.height;
view.frame = frame;
App::I.resize(frame.size.width * view.contentScaleFactor,
frame.size.height * view.contentScaleFactor);
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
CGRect frame = [[UIScreen mainScreen] bounds];
self.view.frame = frame;
App::I.resize(frame.size.width * self.view.contentScaleFactor,
frame.size.height * self.view.contentScaleFactor);
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
@@ -122,6 +158,7 @@ int t_count = 0;
- (void)viewDidAppear:(BOOL)animated
{
[self resignFirstResponder];
[self registerForKeyboardNotifications];
}
- (void)viewDidLoad