简体   繁体   English

iOS UIImage 图像方向不一致

[英]iOS UIImage imageOrientation inconsistent

I'm having an issue in an iOS share extension when users share a photo from the Photos app or from the camera.当用户从照片应用程序或相机共享照片时,我在 iOS 共享扩展中遇到问题。

I'm using the imageRotation property to rotate the image once it's loaded into my application.一旦图像加载到我的应用程序中,我正在使用imageRotation属性旋转图像。

switch (img.imageOrientation) {
    case UIImageOrientationRight:
        rotation = @"90";
        break;

    case UIImageOrientationUp:
        rotation = @"0";
        break;

    case UIImageOrientationDown:
        rotation = @"180";
        break;

    case UIImageOrientationLeft:
        rotation = @"270";
        break;
}

On most devices, this works fine.在大多数设备上,这工作正常。 However, on my personal device (iPhone Xr with 13.4.1), the UIImage is already rotated appropriately and using the rotation value from the switch statement over-rotates (so UIImageOrientationDown will actually display upside down after being rotated by 180 degress).但是,在我的个人设备(13.4.1 的 iPhone Xr)上, UIImage已经适当旋转,并且使用 switch 语句中的旋转值过度旋转(因此UIImageOrientationDown在旋转 180 度后实际上会倒置显示)。 If I don't rotate the image on my device, the images are all oriented correctly, but on others the rotation does need to happen.如果我不在我的设备上旋转图像,则图像的方向都是正确的,但在其他设备上确实需要进行旋转。 I'm not able to find anything in the UIImage I can key off of to prevent the rotation.我在UIImage中找不到任何东西,我可以关闭以防止旋转。

Has anyone else ever run into this situation?有没有其他人遇到过这种情况? Is it a setting on my device?这是我设备上的设置吗? Is there something I can use to determine if I should rotate the image or not?有什么东西可以用来确定是否应该旋转图像?

Thanks in advance.提前致谢。

EDIT: the example code here is missing the 'mirrored' enum options but they also aren't coming up.编辑:这里的示例代码缺少“镜像”枚举选项,但它们也没有出现。 On the problematic device I'm getting the appropriate rotation based on how the camera was held while taking the picture, but performing the rotation is unnecessary在有问题的设备上,我会根据拍照时相机的握持方式进行适当的旋转,但不需要执行旋转

It's because you still not implemented all the case.这是因为你还没有实现所有的情况。 For more information: https://developer.apple.com/documentation/uikit/uiimage/orientation更多信息: https://developer.apple.com/documentation/uikit/uiimage/orientation

It's the same with orientation of the device.这与设备的方向相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM