2012-04-23 30 views
0

假設您有來自圖像選擇器控制器的UIImage。它是否有一個可以檢查圖像是縱向還是橫向的屬性?換句話說,檢查高度是否大於寬度。我查看了參考資料,但沒有看到任何內容。是否UIImage有一個屬性,指示它是否是縱向或橫向

+0

不,我不這麼認爲。 U將不得不檢查控制器的方向。 – mChopsey 2012-04-23 10:38:43

+0

手動檢查高度與寬度不是一個選項嗎? – sooper 2012-04-23 18:33:22

回答

0
if (Yourimage.imageOrientation == UIImageOrientationUp) { 
NSLog(@"portrait"); 
} 
else if (yourimage.imageOrientation == UIImageOrientationLeft || image.imageOrientation == UIImageOrientationRight) { 
NSLog(@"landscape"); 
} 

希望,這將幫助你..

+0

從技術上講,有四種方向對應於縱向圖像:UIImageOrientationDown,UIImageOrientationDownMirrored,UIImageOrientationUpMirrored和UIImageOrientationUp – CedricSoubrie 2014-02-24 11:38:05

1

也許你可以使用imageOrientation但似乎這個代碼更直截了當:

-(BOOL) isPortrait; { 
    return image.height > image.width; 
} 
相關問題