0

我想创建一个如下图所示的示例,而是从照片库中选择图像或使用相机拍照(如 facebook 应用程序)。这个视图是内置的还是我需要创建自定义视图?

例子

4

1 回答 1

3

所以你想要一个 UIActionSheet?

做这个:

UIActionSheet *actionSheet = [[UIActionSheet alloc] 
                                  initWithTitle:@"What do you want to do?" 
                                  delegate:self 
                                  cancelButtonTitle:@"Cancel" 
                                  destructiveButtonTitle:nil 
                                  otherButtonTitles:@"Camera", @"Photos", nil];
    [actionSheet showInView:self.view];
    [actionSheet release];

然后在 clickedButtonAtIndex 做这样的事情:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:@"Camera"]) {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    } 
    else if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:@"Photos"]) {
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
   [self presentModalViewController:picker animated:YES];
   [picker release];
}
于 2012-06-12T18:48:39.177 回答