我正在使用图像拾取器从照片库中选择照片。当我点击按钮时,它会显示图片库。但是当我点击特定的图片时,它会关闭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;
}发布于 2013-04-04 13:09:52
使用以下代码:
在.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-04 13:03:31
- (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-04 13:18:49
最好的方法是将您的Image添加到UIImageView,
- (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];
}https://stackoverflow.com/questions/15802861
复制相似问题