簡體   English   中英

如何在iPhone中使用移動和縮放UIImagePickerController?

[英]How to use move and scale UIImagePickerController in iPhone?

我是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)當我再次導航並選擇另一個圖像時,現在它顯示“移動和縮放”屏幕。 當我單擊選擇按鈕時,它只是顯示一個帶有導航欄的白色屏幕。

有沒有辦法為選擇按鈕設置操作?

我也面臨同樣的問題,我通過使用代碼來解決它,通過這將是有用的。

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

我認為你最好提出這樣的選擇器模態:

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

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

    [self presentModalViewController:picker animated:YES];

然后讓您的圖像顯示在呈現它的viewcontoller的視圖中。

-(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];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM