如何知道横向或纵向模式下的照片?

mik*_*ang 8 iphone photo ipad

我从iPhone/iPad库加载照片,其中大部分都是在纵向模式下,我想知道如何在横向或纵向模式下查看照片?

Bjö*_*lek 12

使用实例的imageOrientation属性UIImage.它将返回这些常量之一.

例:

UIImage*image = //从库加载

if (image.imageOrientation == UIImageOrientationUp) {
    NSLog(@"portrait");
} else if (image.imageOrientation == UIImageOrientationLeft || image.imageOrientation == UIImageOrientationRight) {
    NSLog(@"landscape");
}
Run Code Online (Sandbox Code Playgroud)

  • 这有助于我开始选择专辑,我想为照片添加一些补充信息,我没有意识到这是两个完全不同的东西!当用户使用iPhone的相机拍摄快照时,图像不是直立的,但实际上是逆时针旋转90度.因此,如果你想在`NS`(@"portrait")的`if`块中结束;`那么你将测试`UIImageOrientationLeft || UIImageOrientationRight || UIImageOrientationLeftMirrored || UIImageOrientationRightMirrored`,其余的将是`landscape` (2认同)