I have a problem that is driving me crazy. I’ve been looking the solution for hours and I still can’t find it.
I have a scene (SceneA.cpp) that calls a UIImagePickerController. The way that I do it lies in the following code:
using namespace std;
PhotoLibrary **photos = init];
`interface PhotoLibrary : NSObject<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
property (assign) AppController **appController;property (nonatomic, retain) UIImage *choosenPhoto;
`synthesize appController, choosenPhoto;
NSString *deviceVersion = .systemVersion;
int deviceVersionInt = ;
iOS4 = YES;
iOS4 = NO;
appController = delegate];
if(imagePickerController == nil)
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[appController.viewController presentViewController:imagePickerController animated:YES completion:nil]; //iOS 6
; //iOS 6
self.choosenPhoto = ;
imagePickerController = nil;
~~ (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
[appController.viewController dismissViewControllerAnimated:YES completion:nil]; //iOS 6
imagePickerController = nil;
self = nil;
IOSUtilities works as a bridge between C++ and Objective C. (The file type for the .cpp file is Objective-C++ Source). IOSUtilities calls the UIImagePickerController by creating the PhotoLibrary object and calling the method showImagePicker. Then in my SceneA I call the IOSUtilities method “iosShowPhotoRoll”:
void SceneA::choosePhoto(CCObject *sender)
Everything works like a charm. Now, the problem is that I have another scene called SceneB.cpp that has a CCTextFieldTTF. In SceneB, when I touch the CCTextField the keyboard is shown. Also I implemented the keyboardWillHide and keyboardWillShow methods. Each time the keyboard is shown I move the children of the scene in order to not let the textfield behind the keyboard (by doing this, the user will always see what is typing) and when the keyboard will hide, I move the children to their original position.
HERE IS THE PROBLEM:
When I enter to SceneB +WITHOUT CALLING THE PHOTO ROLL IN SCENEA+, everything works fine; the children moves perfectly well when the keyboard is shown and return to their original position when is hidden. BUT, IF I ENTER TO SCENEA, CALL THE PHOTO ROLL, THEN I ENTER TO SCENEB AND CALL THE KEYBOARD the methods keyboardWillShow and keyboardWillHide are called like 9 times and the children does not return to their original position.
I don’t know if this is a problem of the views (the OpenGL view where Cocos2d-x works) when the UIImagePIckerController is called by the appcontroller.
I can’t seem to find the solution, I’m becoming insane.
Thanks in advance and sorry for the long post.
(Sorry about the formatting of the code, it cannot seem to detect the '`’)