ios keyboard stuff

This commit is contained in:
vladislav.khorev committed 2013-07-15 18:44:22 +00:00
1 parent e9de663388
commit 9a27aacbab
10 files changed
+128 -10

No files matched your search

+23
View File
@@ -8,11 +8,15 @@
#import <Foundation/Foundation.h>
#import <GLKit/GLKit.h>
#import <UIKit/UIKit.h>
#include "include/Utils/Utils.h"
GLKView* defaultView = 0; //Need to be set up by App!
UITextField* extKeyboardTextView = 0;
namespace SE
{
@@ -58,6 +62,25 @@ void IosSwitchToScreen()
{
[defaultView bindDrawable];
}
void ShowKeyboard(std::string text)
{
extKeyboardTextView.text = [NSString stringWithCString:text.c_str() encoding:NSUTF8StringEncoding];
[extKeyboardTextView becomeFirstResponder];
}
void HideKeyboard()
{
[extKeyboardTextView resignFirstResponder];
}
void GuiManagerSetKeyboardText(std::string newText); //Find it in GUIManager.cpp
void SetKeyboardText(const char* newText)
{
GuiManagerSetKeyboardText(newText);
NSLog(@"text: %s", newText);
}
} //namespace SE
+7 -3
View File
@@ -9,6 +9,13 @@
#import "include/Utils/IosApi/ObjC/GLKViewTemplate.h"
#include "include/Utils/IosApi/IosWrapper.h"
#include <string>
namespace SE
{
void ShowKeyboard(std::string text);
}
@implementation GLKViewTemplate
- (id)initWithFrame:(CGRect)frame
@@ -16,7 +23,6 @@
self = [super initWithFrame:frame];
if (self)
{
touchMoved = false;
}
@@ -66,6 +72,4 @@
}
@end
@@ -12,6 +12,15 @@
extern GLKView* defaultView; //Find this in IosApi.mm
extern UITextField* extKeyboardTextView; //Find this in IosApi.mm
namespace SE
{
void SetKeyboardText(const char* newText);
}
@interface ViewControllerTemplate () {
}
@@ -28,6 +37,8 @@ extern GLKView* defaultView; //Find this in IosApi.mm
@synthesize context = _context;
@synthesize effect = _effect;
@synthesize hiddenTextField = _hiddenTextField;
- (void)viewDidLoad
{
@@ -55,6 +66,19 @@ extern GLKView* defaultView; //Find this in IosApi.mm
initWithTarget:self action:@selector(respondToPinch:)];
[self.view addGestureRecognizer:recognizer];
//Keyboard
_hiddenTextField = [[UITextField alloc] initWithFrame:CGRectMake(-200,-200,0,0)];
[self.view addSubview:_hiddenTextField];
extKeyboardTextView = _hiddenTextField;
_hiddenTextField.delegate = self;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReceiveKeyboardNotification:) name:UITextFieldTextDidChangeNotification object:nil];
}
- (void)viewDidUnload
@@ -67,6 +91,8 @@ extern GLKView* defaultView; //Find this in IosApi.mm
[EAGLContext setCurrentContext:nil];
}
self.context = nil;
_hiddenTextField = nil;
}
- (void)didReceiveMemoryWarning
@@ -99,6 +125,26 @@ extern GLKView* defaultView; //Find this in IosApi.mm
SE::AppOnScale(gestureRecognizer.scale);
}
- (void) onReceiveKeyboardNotification:(NSNotification*) notification
{
if (notification.name == UITextFieldTextDidChangeNotification)
{
UITextField* textField = notification.object;
const char* text = [[textField text] UTF8String];
SE::SetKeyboardText(text);
}
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@"Begin");
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSLog(@"End");
}
#pragma mark - GLKView and GLKViewController delegate methods
@@ -115,5 +161,5 @@ extern GLKView* defaultView; //Find this in IosApi.mm
}
@end