4

我是iPhone開發新手。我正在與圖像選取控制器合作,我想移動和縮放從照片庫中選取的圖像,所以我啓用了allowsediting = yes如何在iPhone中使用移動和縮放UIImagePickerController?

而我的選擇器沒有完成方法:

- (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)當我再次導航回來,選擇另一個圖像,現在它顯示「移動和縮放」屏幕。當我點擊選擇按鈕,它只是顯示一個白色的屏幕,沒有導航欄。

是否有任何方法來設置選擇按鈕的動作?

回答

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; 
    } 
} 
+2

方法,shrinkImage從哪裏來?從這一行:UIImage * shrunkenImage = shrinkImage(chosenImage,imageFrame.size); – KKendall

1

我想你會過得更好出示您的選擇器模式是這樣的:

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

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

    [self presentModalViewController:picker animated:YES]; 

然後已經顯示在提交它viewcontoller的視圖圖像。

+2

1爲'picker.allowsEditing = YES;'。 – Kjuly

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]; 
} 
相關問題