使用UIImagePickerController显示相同的默认相机应用程序

时间:2011-11-15 08:26:01

标签: iphone ipad

我们如何使用相机和视频模式以及照片库图标按钮显示UiImagepicker控制器界面,与iPhone的默认相机应用程序相同。

或如何删除取消按钮(显示在相机视图中)并替换为不同的按钮。是否有可能,苹果是否会批准这种做法。

请帮帮我?

1 个答案:

答案 0 :(得分:1)

你可以这样试试。

BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];


    if(hasCamera){

        UIActionSheet *actionSheet; 

        actionSheet = [[[UIActionSheet alloc] initWithTitle:@"Add Photo" 
                                                   delegate:self 
                                          cancelButtonTitle:@"Cancel" 
                                     destructiveButtonTitle:nil 
                                          otherButtonTitles:@"Select from Library", @"Take a New Photo", nil] autorelease];

        actionSheet.actionSheetStyle  = UIBarStyleBlackOpaque;

        [actionSheet showInView:[self view]];
    }

    else {

        UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.allowsEditing    = YES;   
        imagePickerController.delegate          = self;

        imagePickerController.sourceType  = UIImagePickerControllerSourceTypePhotoLibrary;  

        [self presentModalViewController:imagePickerController animated:YES];

        [imagePickerController release];

    }

动态表委托方法

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

    //BOOL                               hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
    UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.allowsEditing    = YES;   
    imagePickerController.delegate          = self;

    if(buttonIndex == 0)
    {
        imagePickerController.sourceType  = UIImagePickerControllerSourceTypePhotoLibrary;  

    }
    else if(buttonIndex == 1)
    {
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

    }
    [self presentModalViewController:imagePickerController animated:YES];

    [imagePickerController release];
}   

图片选择器代理

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    if(image)
    {
        [self.addPhotoButton setBackgroundImage:image forState:UIControlStateNormal];
    }
    [picker dismissModalViewControllerAnimated:YES];

}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissModalViewControllerAnimated:YES];

}