UIImagePickerController预览图像向下移动

时间:2015-02-06 05:05:20

标签: ios objective-c iphone

我知道几年前有关于这个主题的问题,但我认为他们的解决方案已经过时和/或我无法让它们发挥作用。我尝试了所有info.plist更改等。

我正在使用UIImagePickerController。拍摄照片后,预览图像(使用“重新拍摄”和“使用照片选项”)会向下跳跃约20个像素。它似乎占据了mediaTypes工具栏区域。

有关如何防止图像移位的任何建议?这是相关的代码(非常基本的)

- (IBAction)takePhoto:(UIButton *)sender {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [picker prefersStatusBarHidden];
    [self presentViewController:picker animated:YES completion:NULL];
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}

1 个答案:

答案 0 :(得分:3)

在尝试了许多无法正常工作的配置后,我采用了一种简单的方法,将相机视图强制缩小了预览图像使用变换移动的相同像素数,即

picker.cameraViewTransform = CGAffineTransformTranslate(picker.cameraViewTransform, 0.0, 30.0);

整个方法:

- (IBAction)takePhoto:(UIButton *)sender {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;

    picker.cameraViewTransform = CGAffineTransformTranslate(picker.cameraViewTransform, 0.0, 30.0);

    [self presentViewController:picker animated:YES completion:NULL];
}