【问题标题】:Not able to input text by keyboard after UIImagePickerController is dismiss.UIImagePickerController 关闭后无法通过键盘输入文本。
【发布时间】:2013-08-05 08:48:14
【问题描述】:

我在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];
}

当我从库/相机中选择照片时出现问题。其他明智的键盘工作正常。

【问题讨论】:

  • 可能b你的键盘被一个窗口重叠了..尝试使用UIWindow的背景颜色属性进行调试
  • 我。使用 inputaccessoryview 时遇到同样的问题

标签: iphone ios objective-c cocos2d-iphone


【解决方案1】:

使用此代码

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);
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-26
    • 1970-01-01
    • 2014-05-18
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多