2014-05-20 2 views
1

xcode 5에 iOS 7 앱을 개발 중입니다. 카메라 기능을 사용하고 있습니다. 사용자가 내 앱에서 카메라 버튼을 누르면, 그에게 선택권을 주려고합니다. 새로운 사진을 찍거나 "포토 스트림"에서 사진을 선택하십시오. "WhatsApp"와 같은 선택 항목으로 팝업을 표시하거나 Apple Message 앱을 표시하려고합니다.카메라 팝업이있는 iOS 앱

나는 생각했다. 섹션 및 세 개의 셀이있는 테이블 뷰 컨트롤러를 만듭니다. 사진을 찍고 "photostream"에서 선택하고 취소합니다. 이 섹션을 테이블 뷰 맨 아래에 설정하고 배경을 투명하게 만듭니다. 하지만 작동하지 않습니다;)

Google에서도 검색했지만 나에게 도움이되는 내용을 찾지 못했습니다.

아무도 내가 할 수있는 방법을 말해 줄 수 있습니까?

+0

당신이 UIImagePickerController''로 봤어 (https://developer.apple.com/library/ios/documentation/uikit/ :

당신은 UIImagePickerController를 위해이 샘플 코드 형태로 애플에 모습을 가질 수 참조/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html)? – Popeye

+0

[UIActionSheet] (https://developer.apple.com/library/ios/documentation/uikit/reference/uiactionsheet_class/Reference/Reference.html)를 사용했는지 확인하십시오. –

답변

1

시도해보십시오. 당신은

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 

    if (buttonIndex==0) { 
     [self takePictureFromCamera]; 
    } 
    else if (buttonIndex==1) { 
     [self pickImageFromLibrary]; 

    } 
} 

다른 방법 UIActionSheetDelegateUIImagePickerControllerDelegate

- (IBAction)changePhotoButtonPressed:(id)sender { 
    UIActionSheet *actionSheet=[[UIActionSheet alloc] initWithTitle:@"MY APP" 
                  delegate:self 
                cancelButtonTitle: nil 
              destructiveButtonTitle: nil 
                otherButtonTitles:@"Take From Camera",@"Select From Library", @"Cancel", nil]; 
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque; 
    actionSheet.destructiveButtonIndex=2; 
    [actionSheet showInView:[UIApplication sharedApplication].keyWindow]; 
} 

UIActionSheet 위임을 사용해야합니다 :

-(void) pickImageFromLibrary 
{ 
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { 

     UIImagePickerController* imgPicker=[[UIImagePickerController alloc] init]; 
     self.imagePicker = imgPicker; 
     //UI Customization 
     if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { 
      [[self.imagePicker navigationBar] setTintColor:[UIColor whiteColor]]; 
     } 

     self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
     self.imagePicker.delegate = self; 

     [self presentViewController:self.imagePicker animated:YES completion:nil]; 

    } else { 
     NSLog(@"Attempted to pick an image with illegal source type '%d'", UIImagePickerControllerSourceTypePhotoLibrary); 
    } 

} 

-(void) takePictureFromCamera 
{ 

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 

     UIImagePickerController* imgPicker=[[UIImagePickerController alloc] init]; 
     self.imagePicker = imgPicker; 
     self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
     self.imagePicker.delegate = self; 
     if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { 
      [[self.imagePicker navigationBar] setTintColor:[UIColor whiteColor]]; 
     } 

     [self presentViewController:self.imagePicker animated:YES completion:nil]; 

    } else { 
     NSLog(@"Attempted to pick an image with illegal source type '%d'", UIImagePickerControllerSourceTypePhotoLibrary); 

     UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"MY APP" message:@"CAMERA_NOT_AVAILABLE" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     [alert show]; 
    } 
}