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; 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 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{ {
UITouch *touch = [[event allTouches] anyObject]; UITouch *touch = [[event allTouches] anyObject];
@@ -122,6 +158,7 @@ int t_count = 0;
- (void)viewDidAppear:(BOOL)animated - (void)viewDidAppear:(BOOL)animated
{ {
[self resignFirstResponder]; [self resignFirstResponder];
[self registerForKeyboardNotifications];
} }
- (void)viewDidLoad - (void)viewDidLoad

View File

@@ -125,7 +125,7 @@ void App::update(float dt)
//glClear(GL_COLOR_BUFFER_BIT); //glClear(GL_COLOR_BUFFER_BIT);
#ifndef __ANDROID__ #ifndef __ANDROID__
layout.reload(); //layout.reload();
#endif #endif
if (auto* main = layout[main_id]) if (auto* main = layout[main_id])
main->update(width, height, zoom); main->update(width, height, zoom);

View File

@@ -15,7 +15,7 @@
#include "node_panel_stroke.h" #include "node_panel_stroke.h"
#include "node_canvas.h" #include "node_canvas.h"
#ifdef __OBJC__ #if defined(__OBJC__) && defined(__IOS__)
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "GameViewController.h" #import "GameViewController.h"
#endif #endif