{
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];
}
答案 0 :(得分:-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,但是使用它可以在两种模式下拍照。试试这个......