1

我以这种方式将 UIImagePickerController 添加到我的视图中:

- (IBAction)TakeCameraShot:(id)sender{

if ([UIImagePickerController isSourceTypeAvailable:
     UIImagePickerControllerSourceTypeCamera])
{

    // Given by default your orientation is in landscaperight already
    while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications])
        [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;


   /* picker.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    picker.view.backgroundColor = [UIColor clearColor];
    self.modalPresentationStyle = UIModalPresentationCurrentContext;*/
    [self presentViewController:picker animated:YES completion:nil];

   /* picker.view.layer.cornerRadius = 150;
    picker.view.clipsToBounds = YES;
    picker.view.frame = CGRectMake(12, 60, 296, 290);*/

}else{
    NSLog(@"Camera is not available");
    UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Important message" message:@"Unfortunately the camera is not available on your device." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
    [alert1 show];
}
}

我正在尝试使用此代码防止它被旋转到横向

// Given by default your orientation is in landscaperight already
    while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications])
        [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

提供的堆栈溢出的答案还说它只有在 UIviewController 已经设置为仅纵向时才有效,所以这是我从一般应用程序设置(您选择 ipad、iphone 或通用)中所做的。但这不起作用。

4

2 回答 2

1

此代码将在我使用它的 Ipad 上运行,但您需要添加此代码

while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications])
        [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

介绍完之后UIImagePickerController——

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

     while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications])
        [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
    [self presentViewController:picker animated:YES completion:nil];

while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications])
     [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

这也将在 ipod 上工作,但在 ipod 上它仍然会为您提供旋转图像,如果您想要始终在 ipod 中使用肖像图像,您需要像这样更改它们的方向

UIImageOrientationRight -- 这个方向是当相机在 potrait 中时单击图像时 UIImageOrientationUp -- 当相机在横向时左

UIImageOrientationDown -- 这是当相机是横向的时候

UIImageOrientationLeft - 这是相机倒置的时候

现在除了首先将图像方向更改为 UIImageOrientationRight 之外的所有其他三个条件。

这可以通过检查即将到来的图像的方向并应用新的方向来完成。

于 2013-09-17T17:42:06.930 回答
0

只需为 UIImagePickerController 创建一个类别并将这行代码放在该类中

  • (BOOL)shouldAutorotate{ 返回 NO; }
于 2014-07-31T14:45:46.193 回答