2013-07-25 66 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开发和提出问题。有兴趣的人?

相关问题