仅在iOS环境中拍摄照片

时间:2012-07-13 09:05:11

标签: ios camera landscape

我有一个仅在横向模式下运行的应用。当我展示相机拍照时,它将屏幕显示为横向,但实时预览会旋转。当我拍照时,静态预览是正确的。

我尝试用这个旋转相机图像:

self.navigationController.navigationBarHidden=YES;
UIImagePickerController *picker=[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls=YES;
[picker setCameraFlashMode:UIImagePickerControllerCameraFlashModeOff];
CGAffineTransform transform=picker.view.transform;
transform= CGAffineTransformMakeRotation(-90*M_PI/180);
[picker setCameraViewTransform:transform];
[self presentModalViewController:picker animated:YES];
[picker release];

现在我以正确的方式进行实时预览但是一个小的观看区域(可能是因为它的视图是纵向的?)。静态预览再次正确。

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

现在你想在风景和肖像模式下拍照?如果以下是我的代码,但在这里我以纵向模式预览oly,如果你想在横向模式下你必须使用自定义方法创建UIImagePickerViewController,因为预览只能在纵向模式下获得。

但是你可以在你想要的任何一种模式下拍照,看下面这段代码可能对你有帮助..

-(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])
    {
        NSLog(@"called");
        // 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];
}

答案 1 :(得分:0)

我的方法是强制UIImagePickerController以横向模式显示并保持。真实的+这里是如果你只是在用户试图以肖像方式打开时才显示警告,那么用户仍然可以在风景中开始,但在拍摄照片时会旋转为肖像。

@implementation UIImagePickerController (noRotation)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation /* iOS 5 */
{
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

- (NSUInteger)supportedInterfaceOrientations /* iOS 6 */
{
    return UIInterfaceOrientationMaskLandscape;
}

@end