24
24
25
25
#import " CCTextField.h"
26
26
#import " CCControlSubclass.h"
27
+ #import " CCDirector_Private.h"
27
28
28
- @implementation CCTextField
29
+ @implementation CCTextField {
30
+ #if defined(APPORTABLE)
31
+ BOOL _textFieldIsEditing;
32
+ #endif
33
+ }
29
34
30
35
+ (id ) textFieldWithSpriteFrame : (CCSpriteFrame *)frame
31
36
{
@@ -189,6 +194,10 @@ - (void) layout
189
194
#ifdef __CC_PLATFORM_IOS
190
195
- (void )textFieldDidBeginEditing : (UITextField *)textField
191
196
{
197
+ #if defined(APPORTABLE)
198
+ _textFieldIsEditing = YES ;
199
+ #endif
200
+
192
201
if (_keyboardIsShown)
193
202
{
194
203
[self focusOnTextField ];
@@ -197,6 +206,9 @@ - (void)textFieldDidBeginEditing:(UITextField *)textField
197
206
198
207
- (void )textFieldDidEndEditing : (UITextField *)textField
199
208
{
209
+ #if defined(APPORTABLE)
210
+ _textFieldIsEditing = NO ;
211
+ #endif
200
212
[self endFocusingOnTextField ];
201
213
}
202
214
@@ -256,7 +268,13 @@ - (void)keyboardWasShown:(NSNotification*)notification
256
268
257
269
_keyboardHeight = kbSize.height ;
258
270
259
- if (_textField.isEditing )
271
+ BOOL focusOnTextField = _textField.isEditing ;
272
+
273
+ #if defined(APPORTABLE)
274
+ focusOnTextField = _textFieldIsEditing;
275
+ #endif
276
+
277
+ if (focusOnTextField)
260
278
{
261
279
[self focusOnTextField ];
262
280
}
@@ -275,11 +293,18 @@ - (void) keyboardWillBeHidden:(NSNotification*) notification
275
293
276
294
- (void ) focusOnTextField
277
295
{
296
+ #if defined(APPORTABLE)
297
+ // Ensure that all textfields have actually been positioned before checkings textField.frame property,
298
+ // it's possible for the apportable keyboard notification to be fired before the mainloop has had a chance to kick of a scheduler update
299
+ CCDirector *director = [CCDirector sharedDirector ];
300
+ [director.scheduler update: 0.0 ];
301
+ #endif
302
+
278
303
CGSize windowSize = [[CCDirector sharedDirector ] viewSize ];
279
304
280
305
// Find the location of the textField
281
306
float fieldCenterY = _textField.frame .origin .y - (_textField.frame .size .height /2 );
282
-
307
+
283
308
// Upper third part of the screen
284
309
float upperThirdHeight = windowSize.height / 3 ;
285
310
@@ -290,8 +315,16 @@ - (void) focusOnTextField
290
315
// Calculate offset
291
316
float dstYLocation = windowSize.height / 4 ;
292
317
float offset = -(fieldCenterY - dstYLocation);
318
+
293
319
if (offset < -_keyboardHeight) offset = -_keyboardHeight;
294
320
321
+ #if defined(APPORTABLE)
322
+ // Apportable does not support changing the openglview position, so we will just change the current scenes position instead
323
+ CCScene *runningScene = [[CCDirector sharedDirector ] runningScene ];
324
+ CGPoint newPosition = runningScene.position ;
325
+ newPosition.y = (offset * -1 );
326
+ runningScene.position = newPosition;
327
+ #else
295
328
// Calcualte target frame
296
329
UIView* view = [[CCDirector sharedDirector ] view ];
297
330
CGRect frame = view.frame ;
@@ -303,16 +336,23 @@ - (void) focusOnTextField
303
336
[UIView setAnimationDuration: 0 .2f ];
304
337
305
338
view.frame = frame;
306
-
307
339
[UIView commitAnimations ];
340
+ #endif
308
341
}
309
342
}
310
343
311
344
- (void ) endFocusingOnTextField
312
345
{
313
- UIView* view = [[CCDirector sharedDirector ] view ];
314
-
315
346
// Slide the main view back down
347
+
348
+ #if defined(APPORTABLE)
349
+ // Apportable does not support changing the openglview position, so we will just change the current scenes position instead
350
+ CCScene *runningScene = [[CCDirector sharedDirector ] runningScene ];
351
+ CGPoint newPosition = CGPointZero;
352
+ newPosition.y = 0 .0f ;
353
+ runningScene.position = newPosition;
354
+ #else
355
+ UIView* view = [[CCDirector sharedDirector ] view ];
316
356
[UIView beginAnimations: @" textFieldAnim" context: nil ];
317
357
[UIView setAnimationBeginsFromCurrentState: YES ];
318
358
[UIView setAnimationDuration: 0 .2f ];
@@ -322,6 +362,8 @@ - (void) endFocusingOnTextField
322
362
view.frame = frame;
323
363
324
364
[UIView commitAnimations ];
365
+ #endif
366
+
325
367
}
326
368
327
369
#endif
0 commit comments