1
{      
    self.imagePickerController = [[[UIImagePickerController alloc] init ] autorelease];
    imagePickerController.view.frame=CGRectMake(0, 0, 1024, 768);
    self.imagePickerController.delegate = self;
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

    //Set Notifications so that when user rotates phone, the orientation is reset to landscape.
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

    //Refer to the method didRotate:   
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(didRotate:)
                                                 name:@"UIDeviceOrientationDidChangeNotification" object:nil];

    //Set the picker source as the camera   
    self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

    //Bring in the picker view   
    [self presentModalViewController:self.imagePickerController animated:YES];
}
4

1 回答 1

-2

这是我的代码,这可能会对您有所帮助

-(void)cameraAction
{

// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

// Set source to the camera
imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker.delegate = self;

// Allow editing of image ?

imagePicker.allowsEditing = NO;


if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    // Show image picker
    [self presentModalViewController:imagePicker animated:YES];  

}
else{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing the camera"
                                                    message:@"Camera did not respond" delegate:nil
                                          cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release];
 }

}
 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    [picker release];

    [self dismissModalViewControllerAnimated:NO];

    editImageView=[[EditImageViewController alloc] initWithNibName:@"EditImageViewController" bundle:[NSBundle mainBundle]];
    editImageView.delegate=self;
    [self presentModalViewController:editImageView animated:YES];
    [editImageView.imgView setImage:image];

}

但这不是自定义 uiimagepickerviewcontroller 但使用它你可以在两种模式下拍照。试试这个...

于 2012-07-28T09:49:04.327 回答