2014-05-11 1 views
0

UIImagePickerController을 사용자 지정 cameraOverlayView으로 프로그래밍하려고합니다. 내가 UIImagePickerControllertakePicture 메서드를 호출하면 UIView이 "사진 사용"을 선택할 수있는 선택기 대신 흰색 화면으로 변경됩니다. 어떻게 후속 UIView을 공백 대신 피커로 설정할 수 있습니까? UIView?takePicture 메서드가 호출 된 후 UIImagePickerController가 흰 화면으로 바뀜

나는 포함했다 아래에있는 내 코드 :

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(applicationDidBecomeActive) 
              name:UIApplicationDidBecomeActiveNotification 
              object:nil]; 
} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 


-(void)dealloc 
{ 
[[NSNotificationCenter defaultCenter] removeObserver:self 
               name:UIApplicationDidBecomeActiveNotification 
               object:nil]; 
} 

- (void)applicationDidBecomeActive 
{ 




//Start the camera up 

_imageViewPickerController = [[UIImagePickerController alloc] init]; 

//Hide default UI elements 

_imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 
_imageViewPickerController.showsCameraControls = NO; 
_imageViewPickerController.navigationBarHidden = YES; 
_imageViewPickerController.toolbarHidden = YES; 

//Start the button overlay 

UIView *btnView = [[UIView alloc] initWithFrame:_imageViewPickerController.view.bounds]; 
btnView.opaque = NO; 
btnView.clipsToBounds = YES; 

//Start up the button 
UIButton *snapButton = [[UIButton alloc] initWithFrame:CGRectMake(-6, 504, 65, 65)]; 
snapButton.alpha = 0.5; 
snapButton.transform = CGAffineTransformMakeRotation(DEGREES_RADIANS(90)); 
[snapButton addTarget:self action:@selector(snapThat) forControlEvents:UIControlEventTouchUpInside]; 

//Set the button's picture 
UIImage *snapButtonImage = [UIImage imageNamed:@"Button.png"]; 
[snapButton setImage:snapButtonImage forState:UIControlStateNormal]; 

//Add button to the overlay 
[btnView addSubview:snapButton]; 

//Overlay button view 

_imageViewPickerController.cameraOverlayView = btnView; 

//Fix for iPhone 5 and make fullscreen 

CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -55.0); 
CGAffineTransform scale = CGAffineTransformMakeScale(1.333333, 1.333333); 
CGAffineTransform rotate = CGAffineTransformMakeRotation(DEGREES_RADIANS(180)); 
CGAffineTransform transform = CGAffineTransformConcat(translate, scale); 
transform = CGAffineTransformConcat(transform, rotate); 
_imageViewPickerController.cameraViewTransform = transform; 

//Let's present it all 

[self presentViewController:_imageViewPickerController 
        animated:NO 
       completion:NULL]; 


} 

- (void)snapThat { 
[_imageViewPickerController takePicture]; 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
// Save photo 
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; 
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) 
{ 
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 
    UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil); 
} 
[picker dismissViewControllerAnimated:YES completion:NULL]; 
} 

편집 : 나는 이것을 포함하려면 코드를 수정 한, 나는 여전히 빈 UIView의 수 : [self presentViewController:_imageViewPickerController animated:NO completion:NULL]; 이이 영상과 수익을 저장하지 않나요을 카메라보기로 나에게?

답변

0

내 UIImagePickerController의 takePicture 메서드를 호출하면 UIView가 "사진 사용"을 선택할 수있는 선택기 대신 흰색 화면으로 변경됩니다.

때문에 당신이 당신의 didFinishPickingMediaWithInfo: 구현에 dismissViewControllerAnimated:를 호출 것을하고있어. 카메라 인터페이스를 닫지 않으려면 닫지 마십시오.

자동 두 번째보기가 없습니다 ("사진 사용"또는 무엇이든 선택할 수 있음). 원한다면 자신 만의 두 번째보기 컨트롤러를 만들어 UIImagePickerController (탐색 컨트롤러)에 밀어 넣어야합니다.

+0

여기에 대해 더 자세히 설명합니다 : http://www.apeth.com/iOSBook/ch30.html#_using_the_camera – matt

+0

그리고 두 번째보기 컨트롤러를 만들고 UIImagePickerController에 밀어 넣으면 다운로드 할 수있는 예제가 있습니다. 이 이미지를 사용할지 여부를 결정하십시오. https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch17p704takeAPicture2/ch30p962takeAPicture2/ViewController.m – matt

+0

내 질문과 관련하여 OP를 수정했습니다. . 내 코드가 모두 작동해야하는 것 같습니다. 당신이 더 명확하게 신경 쓰지 않는다면 나는 정말로 그것을 고맙게 여길 것이다. – mattchue

관련 문제