{
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];
}
質問する
454 次
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 に答える