2014-05-20 3 views
1

Je développe une application iOS 7 en xcode 5. J'utilise la fonctionnalité de la caméra. Lorsque l'utilisateur appuie sur le bouton de l'appareil photo dans mon application, je veux lui donner le choix: prendre une nouvelle photo ou choisir une photo dans le "photostream". Je veux montrer un popup avec le choix comme "WhatsApp", ou comme l'application Apple Message.iOS application avec caméra popup

Je pensais; Je crée un contrôleur Table View avec une section et trois cellules: prenez une photo, choisissez "photostream" et annulez. J'ai mis cette section au bas de la vue Table et rendre l'arrière-plan transparent. Mais ça ne marche pas;)

J'ai aussi cherché sur Google, mais je n'ai rien trouvé qui puisse m'aider.

Quelqu'un peut-il me dire comment je pourrais le faire?

+0

Avez-vous étudié 'UIImagePickerController' (https://developer.apple.com/library/ios/documentation/uikit/ reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html)? – Popeye

+0

Vérifiez qu'ils ont utilisé [UIActionSheet] (https://developer.apple.com/library/ios/documentation/uikit/reference/uiactionsheet_class/Reference/Reference.html) –

Répondre

1

Essayez ceci. Vous devez utiliser UIActionSheetDelegate et UIImagePickerControllerDelegate

- (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 Délégué

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

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

    } 
} 

Autres méthodes:

-(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]; 
    } 
}