我在cocos2D
开发了我的应用程序。
我使用了自定义UIView
,其中包含2 UITextField
和1 UITextView
,并且还具有获取照片的功能。
在我的应用程序中,我使用UIImagePickerController
从相机/库中拍摄图像。所有功能都正常工作,但是当我从相机/图书馆选择照片然后解雇我的imagePicker
后,我无法再次在UITextField
中输入文字。
我也看这个Question,然后关注它们。
我的相关代码是:
#pragma Mark -
#pragma Mark - ActionSheet Delegate Methods
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIImagePickerController *imgPicker=[[UIImagePickerController alloc] init];
imgPicker.delegate=self;
imgPicker.wantsFullScreenLayout = YES;
imgPicker.allowsEditing=YES;
if(buttonIndex == 0)
{
isVideoTakenFromCamera = YES;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
else
imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
else if (buttonIndex==1)
{
isVideoTakenFromCamera = NO;
imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[[XPSModal sharedInstance] hideWindow]; // it is my custom UIView.
[[CCDirector sharedDirector] presentViewController:imgPicker animated:YES completion:nil];
// [[[[UIApplication sharedApplication] delegate] window] makeKeyWindow]; i alsos put here this code but it is not works for me.
}
#pragma mark -
#pragma mark - UIImagePickerController Delegate Method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage];
img = [self resizeImage:img];
[self.btnTakePhoto setImage:img forState:UIControlStateNormal];
[[CCDirector sharedDirector] dismissViewControllerAnimated:YES completion:nil];
[[XPSModal sharedInstance] showWindow]; // it is my custom UIView.
[[[[UIApplication sharedApplication] delegate] window] makeKeyWindow];
}
从库/相机中选择照片时会出现问题。其他智能键盘工作正常。
答案 0 :(得分:0)
使用此代码
Declare this `UIImagePickerController *imagePicker;` as a global then follow this code..
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==1)
{
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:imagePicker animated:YES];
} else if(buttonIndex==2) {
if ( [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePicker animated:YES];
}
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[imagePicker dismissModalViewControllerAnimated:YES];
_profilePicImgView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(_profilePicImgView.image, nil, nil, nil);
}
}