xcode 从相机拍照后旋转 UIImageView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15167402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:53:06  来源:igfitidea点击:

UIImageView is rotated after taking picture from camera

iosxcodeuiimageview

提问by Robert Hill

I am seeing some peculiar behavior in an iPad application. I have a UIImageView and I am capturing from the camera. When in Portrait mode and I take a picture it appears correctly in the UIImageView when I respond to the didFinishPickingMediaWithInfo event. However, when I return to the UIIMageView later to redisplay the saved photograph it automatically rotates the image 90 degrees. Rotating the device continues to show the image rotated 90 degrees.

我在 iPad 应用程序中看到了一些奇怪的行为。我有一个 UIImageView 并且我正在从相机中捕捉。当我在人像模式下拍照时,当我响应 didFinishPickingMediaWithInfo 事件时,它会正确显示在 UIImageView 中。但是,当我稍后返回 UIIMageView 以重新显示保存的照片时,它会自动将图像旋转 90 度。旋转设备继续显示旋转 90 度的图像。

Is there a way to determine the orientation used when the image is captured and is that the method that should be used to re-display the image?

有没有办法确定捕获图像时使用的方向,以及应该使用这种方法重新显示图像?

Any help would be appreciated. I searched but could not find anything specific to this.

任何帮助,将不胜感激。我进行了搜索,但找不到任何特定于此的内容。

回答by Robert Hill

I'm all set with this. The responses at

我已经准备好了。回应在

iOS UIImagePickerController result image orientation after upload

上传后 iOS UIImagePickerController 结果图像方向

worked for me. Immediately after capturing the image I'm checking the rotation and adjusting as necessary per the code example on this thread.

对我来说有效。捕获图像后,我立即根据此线程上的代码示例检查旋转并根据需要进行调整。

Thanks for all that responded!

感谢所有回复!

回答by Obj-Swift

Try this: add this to viewWillAppear or wherever you desire:

试试这个:将它添加到 viewWillAppear 或任何你想要的地方:

[self updateLayoutForNewOrientation: self.interfaceOrientation];

and add this method:

并添加此方法:

- (void) updateLayoutForNewOrientation: (UIInterfaceOrientation) orientation {
if (UIInterfaceOrientationIsLandscape(orientation)) {
// do something
    } else {
//do something
   }
}