2013-07-25 3 views
3

UIImagePickerController (photoPicker)을 사용하여 카메라로 사진을 찍고 (allowEditing = YES) 편집하십시오. 사용자는 photoPicker.view 버튼으로 카메라와 라이브러리를 전환 할 수 있지만 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

나는 약간의 해킹을 생각해 내게 맞습니다. 조금 새로운 것이므로 다른 방법을 찾지 못해 원하는대로 최적화하십시오.

기본적인 아이디어는 바로하기 전에 내가 말했듯이

여기

내 샘플 코드

@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 



} 

이다 takePicture UIImagePickerController를] 호출하는 방법을 수행하는 기본 카메라 버튼을 통해 보이지 않는 버튼을 만드는 것입니다 카메라가 준비되었는지 확인하십시오. 당신은 그것을하는 방법에 대한 stackoverflow에 대한 답변을 찾을 수 있습니다.

이 코드는 너무 빨라서 편집 또는 대체 솔루션을 환영합니다.

ios dev에 대해 더 많이 배우고 질문 할 수 있도록 dev buddy가 필요합니다. 관심있는 사람?

관련 문제