1

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

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

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

现在我以正确的方式获得实时预览,但观看区域很小(可能是因为)它的视图是纵向的?)。仍然预览是正确的。

我该如何解决?

4

2 回答 2

0

我的方法是强制 UIImagePickerController 显示并保持横向模式。真正的 + 是,如果您仅在用户尝试以纵向打开时显示警报,则用户仍然可能以横向开始,但在拍照时旋转为纵向。

@implementation UIImagePickerController (noRotation)

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

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

@end
于 2012-11-20T16:49:53.510 回答
0

现在你想在风景和肖像模式下拍照?如果是这样,下面是我的代码,但这里 Iget preview in portrait mode 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];
}
于 2012-07-28T10:08:36.010 回答