2013-07-25 99 views
3

我用UIImagePickerControllerphotoPicker)用相機拍照,然後編輯這些圖片(allowEditing = YES)。用戶可以使用photoPicker.view中的按鈕在Camera和Library之間切換,但當photoPicker處於編輯模式時,我想要刪除此按鈕。進入UIImagePickerController編輯模式

photoLibrarySourceType撿拾工具使用推,以顯示編輯模式,所以用這種方法的工作原理:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated 
{ 
    if (navigationController == photoPicker) { 
     NSLog(@"navigation "); 
     if ([navigationController.viewControllers indexOfObject:viewController] == 1) 
     { 
      // If second UIViewController, set your overlay. 
      NSLog(@"editing"); 
     } 
    } 
} 

但在cameraSourceType,有攝像頭和編輯模式之間沒有導航。

+0

你有沒有找到解決方案,我有同樣的問題:( –

回答

0

我想出了一個小黑客,它適用於我。我仍然有點新,所以請儘量優化,因爲我找不到另一種方式來做到這一點。

的基本思想是在執行調用[的UIImagePickerController takePicture]

這裏是我的示例代碼

@implementation myViewController 
{ 
    UIImagePickerController *myImagePickerController; 
    UIButton * fakeCameraButton; 


} 

- (IBAction)showImagePicker:(id)sender{ 

    // accessible camera validations implied 
    myImagePickerController = [[UIImagePickerController alloc]init]; 
    myImagePickerController.sourceType=UIImagePickerControllerSourceTypeCamera;  
    myImagePickerController.showsCameraControls = YES; 
    myImagePickerController.delegate=self; 
    myImagePickerController.allowsEditing=YES; 

    CGFloat myViewHeight = 100; // you play around with the positions to get your desired frame size. This worked for me 
    UIView * myView = [[UIView alloc] initWithFrame:CGRectMake(0, myImagePickerController.view.frame.size.height - myViewheight, picker.view.frame.size.width, myViewheight)]; 

    fakeCameraButton = [[UIButton alloc] initWithFrame:CGRectMake(myView.frame.size.width/2 - 30, myView.frame.size.height/2-15, 60, 60)];// position it over the default camera button 
    [fakeCameraButton addTarget:self action:@selector(cameraButtonPressed) forControlEvents:UIControlEventTouchUpInside]; 
    [fakeCameraButton setTitle:@"" forState:UIControlStateNormal]; 

    [myView addSubview:fakeCameraButton]; 
    myImagePickerController.cameraOverlayView = myView; 
    [self presentViewController:myImagePickerController animated:YES completion:nil]; 


} 

-(void)cameraButtonPressed{ 

    // Make sure you check if camera is ready before this method. 
    [myImagePickerController takePicture]; 

    // you are in editing/preview mode here if allowsEditing = YES 

    // you can remove all your custom overlay views by 
    myImagePickerController.cameraOverlay = nil 



} 

就像我以前說過只是做一個方法的默認攝像頭按鈕,創建一個不可見的按鈕確定你檢查相機是否準備好。你可以在這裏找到關於如何做到這一點stackoverflow的答案。

此代碼可能會吸引所以編輯或替代解決方案歡迎。

我需要開發夥伴幫助我瞭解更多關於ios開發和提出問題。有興趣的人?

相關問題