2011-11-15 54 views

回答

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

    } 

Actionsheet委托方法

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

} 
+0

- 我想表明在相机屏幕只有照片库中选择用户。与默认iPhone相机应用程序相同。对我而言,最后一个选择是使用重叠属性来定制每一件事情。如果我可以在不定制的情况下实现此功能,那将会更好。 –

相关问题