resize view when keyboard appears
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user