2012-07-13 61 views
1

我有一个只能在横向模式下运行的应用程序。当我将相机拍照时,它会将屏幕显示为风景,但实时预览会旋转。当我拍照时,静止的预览是正确的。仅在iOS环境中拍摄照片应用程序

我试图与该摄像机图像旋转:

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

现在我得到了实时预览的正确方法一轮,但一个小的可视面积(可能是因为)它的观点是在纵向)?仍然预览是正确的。

我该如何解决这个问题?

回答

0

现在你想在横向和纵向模式下拍照?如果下面是我的代码,但在这里Iget预览肖像模式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]; 
} 
+0

继承的UIImagePickerController或迫使它景观气馁,看到http://stackoverflow.com/a/16346664/568529 – akaralar 2013-11-14 23:27:00

0

我的做法是强制的UIImagePickerController显示和在横向模式下保持。真正的+这里是,如果您在用户尝试打开纵向时只显示警告,用户仍可能开始横向拍摄,但在拍摄照片时会旋转至肖像。

@implementation UIImagePickerController (noRotation) 

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

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

@end 
+1

的工作,但有一个严重的错误(与iOS 6.1测试)。它可以正确录制,但在录制过程中会将图像旋转到纵向。 – 2013-03-13 01:49:27

相关问题