2017-09-03 46 views
0

以下swift語句的objc代碼是什麼?什麼是UIDevice.currentDevice()。orientation.isLandscape的目標c等價物?

if (UIDevice.currentDevice().orientation.isLandscape) 

我想通了,至今

if ([[UIDevice currentDevice] orientation]) 
+1

我認爲你可以使用這個UIDeviceOrientationIsLandscape([的UIDevice currentDevice] .orientation), – 3stud1ant3

+0

@ 3stud1ant3謝謝你的答覆。我檢查viewWillTransitionToSize它工作時,我旋轉到風景,我也加入如果(UIDeviceOrientationIsPortrait([UIDevice currentDevice] .orientation)) { {NSK(@「Portrait」); } 但它不起作用 – ios

+0

請檢查當你旋轉到肖像,你的viewWillTransitionToSize方法被調用或不是 – 3stud1ant3

回答

1

從蘋果文檔: -

BOOL UIDeviceOrientationIsLandscape(UIDeviceOrientation orientation); 

返回一個布爾值,指示設備是否處於 橫向。

那麼試試這個: -

if(UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){ 
    //True if landscape is on 
} 
+0

謝謝你的回覆。工作在景觀,但不是肖像請閱讀對問題的最後評論 – ios

+0

@ios您在檢查這些條件之前是否已啓用'beginGeneratingDeviceOrientationNotifications'像這樣的[[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]? –

+0

謝謝你的回覆。在重新啓動模擬器後工作。我是iOS的新手,我必須在條件之前放置[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]嗎? – ios

1
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation; 
BOOL isLandscape = UIDeviceOrientationIsLandscape(orientation); 
if (isLandscape) { 
    NSLog(@"Landscape orientation") 
    //Do the work 
} 
相關問題