From d01ec65cad079a0363d1d3ea5569d096929e3c64 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Sat, 29 Jul 2017 15:02:27 +0100 Subject: [PATCH] resize view when keyboard appears --- PanoPainter/GameViewController.m | 37 ++++++++++++++++++++++++++++++++ engine/app.cpp | 2 +- engine/app.h | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/PanoPainter/GameViewController.m b/PanoPainter/GameViewController.m index e636d50..d66940e 100644 --- a/PanoPainter/GameViewController.m +++ b/PanoPainter/GameViewController.m @@ -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 *)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 diff --git a/engine/app.cpp b/engine/app.cpp index cb2332e..da451fd 100644 --- a/engine/app.cpp +++ b/engine/app.cpp @@ -125,7 +125,7 @@ void App::update(float dt) //glClear(GL_COLOR_BUFFER_BIT); #ifndef __ANDROID__ - layout.reload(); + //layout.reload(); #endif if (auto* main = layout[main_id]) main->update(width, height, zoom); diff --git a/engine/app.h b/engine/app.h index 7110c57..ccceb2e 100644 --- a/engine/app.h +++ b/engine/app.h @@ -15,7 +15,7 @@ #include "node_panel_stroke.h" #include "node_canvas.h" -#ifdef __OBJC__ +#if defined(__OBJC__) && defined(__IOS__) #import #import "GameViewController.h" #endif