4

我是 iPhone 开发的新手。我正在使用图像选择器控制器,我想在其中移动和缩放从照片库中选择的图像,所以我启用了allowsediting = yes.

我的选择器确实完成了方法:

 - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Access the uncropped image from info dictionary

    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    self.imgForDisplay.image=[self scaleAndRotateImage:image];
    self.imagePicker.allowsEditing = YES;


    ImageDetailsViewController *imageDetailsVC = [[ImageDetailsViewController alloc] init];
    imageDetailsVC.imagedisplay.image = self.imgForDisplay.image;
    [picker pushViewController:imageDetailsVC animated:YES];



//[picker dismissModalViewControllerAnimated:YES];

}

然后我推另一个视图控制器,我想在其中显示选择的图像。

这里我有两个问题:

1)当我选择图像时,它导航到另一个没有“移动和缩放”屏幕的视图,但图像现在在导航时显示在 ImageDetailsViewController 中。

2)当我再次导航并选择另一个图像时,现在它显示“移动和缩放”屏幕。当我单击选择按钮时,它只是显示没有导航栏的白屏。

有没有办法设置选择按钮的动作?

4

3 回答 3

2

我也面临同样的问题,我通过使用代码解决了这个问题,通过这个它会很有用。

 - (void)imagePickerController:(UIImagePickerController *)picker  
    didFinishPickingMediaWithInfo:(NSDictionary *)info { 
        self.lastChosenMediaType = [info objectForKey:UIImagePickerControllerMediaType]; 
        if ([lastChosenMediaType isEqual:(NSString *)kUTTypeImage]) { 
            UIImage *chosenImage = [info objectForKey:UIImagePickerControllerEditedImage]; 
            UIImage *shrunkenImage = shrinkImage(chosenImage, imageFrame.size); 
            self.image = shrunkenImage; 
        } else if ([lastChosenMediaType isEqual:(NSString *)kUTTypeMovie]) { 
            self.movieURL = [info objectForKey:UIImagePickerControllerMediaURL]; 
        } 

        ImageSelectionView *imageSelectionVC = [[ImageSelectionView alloc] init];
        imageSelectionVC.theImage = image;
        [picker pushViewController:imageSelectionVC animated:YES];
        imageSelectionVC.dismissDelegate =self;


       // [picker dismissModalViewControllerAnimated:YES]; 
    } 

'

-(void)updateDisplay { 
    if ([lastChosenMediaType isEqual:(NSString *)kUTTypeImage]) { 
        imageView.image = image; 
        imageView.hidden = NO; 
        moviePlayerController.view.hidden = YES; 
    } else if ([lastChosenMediaType isEqual:(NSString *)kUTTypeMovie]) { 
        [self.moviePlayerController.view removeFromSuperview]; 
        self.moviePlayerController = [[MPMoviePlayerController alloc] 
                                       initWithContentURL:movieURL] ; 
        moviePlayerController.view.frame = imageFrame; 
        moviePlayerController.view.clipsToBounds = YES; 
        [self.view addSubview:moviePlayerController.view]; 
        imageView.hidden = YES; 
    } 
}
于 2012-05-18T12:55:35.180 回答
1

我认为你最好像这样展示你的选择器模式:

 if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];

    picker.allowsEditing = YES;
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentModalViewController:picker animated:YES];

然后让您的图像显示在显示它的视图控制器的视图中。

于 2012-05-04T16:01:27.913 回答
0
-(IBAction)Btn_AddImage:(id)sender
{
    UIImagePickerController *Image_Picker=[[UIImagePickerController alloc]init];
    Image_Picker.delegate=self;
    Image_Picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:Image_Picker animated:YES completion:Nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSData  *Data=UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"], 1);
    UIImage *Cust_Image=[[UIImage alloc]initWithData:Data];
    Profile_Image.image=Cust_Image;
    [picker dismissViewControllerAnimated:YES completion:Nil];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:Nil];
}
于 2013-09-20T14:24:31.940 回答