1

我使用图像选择器从照片库中选择照片。当我单击按钮时,它会显示照片库。但是当我单击特定图像时,它会关闭 modalView 并且图像不会加载到查看。

代码:

-(void)showcamera:(id)sender{

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc]init];
    imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentModalViewController:imagePickerController animated:YES];

}


- (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo
{

    // Dismiss the image selection, hide the picker and

    //show the image view with the picked image

    [picker dismissModalViewControllerAnimated:YES];
    UIImage *newImage = image;


}
4

3 回答 3

1
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    imgPicked = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        [imagePickerController dismissModalViewControllerAnimated:YES];
    }
}

在 .h 中声明

UIImage *imgPicked; 

ViewDidLoad

imgPicked = [[UIImage alloc]init];
于 2013-04-04T05:03:30.940 回答
1

使用此代码:

在 .h 文件中

{
UIImageView *newImage;
    UIImagePickerController *imagePicker;
}

在 .m 文件中

- (void)imageTaped:(UITapGestureRecognizer *)tapGesture {
    imagePicker=[[UIImagePickerController alloc]init];

    imagePicker.delegate = self;

    imagePicker.allowsEditing =NO;

    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentModalViewController:imagePicker animated:YES];

}



-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    //release picker
    [picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    //set image


    newImage = [[UIImageView alloc] initWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
    [self.view addSubview:mewImage];
    [picker dismissModalViewControllerAnimated:YES];
}
于 2013-04-04T05:09:51.673 回答
0

最好的方法是将您添加ImageUIImageView,

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
     UIImageView *ImgView = [[UIImageView alloc] initWithFrame:CGRectMake(@"As U Want")];
     ImgView.image = image;
    [self.View addSubview: ImgView];


    [picker dismissModalViewControllerAnimated:YES];
}
于 2013-04-04T05:18:48.877 回答