IOS 特定於裝置的開發:處理基本方向

來源:互聯網
上載者:User

標籤:

UIDevice類使用內建的orientation屬性擷取裝置的物理方向。IOS裝置支援這個屬性的7個可能的值。

    》UIDeviceOrientationUnknown:方向目前未知。

    》UIDeviceOrientationPortrait:Home鍵在下。

    》UIDeviceOrientationPortraitUpsideDown:Home鍵在上

    》UIDeviceOrientationLandscapeLeft:Home鍵在左邊

    》UIDeviceOrientationLandscapeRight:Home鍵在右邊

    》UIDeviceOrientationFaceUp:裝置正面朝上

    》UIDeviceOrientationFaceDown:裝置正面朝下

IOS 提供了兩個內建宏,幫組確定裝置方向枚舉值是縱向還是橫向的:既UIDeviceOrientationIsPortrait()和UIDeviceOrientationIsLandscape().能夠很方便的擴充UIDevice類,提供這些測試作為內建的裝置屬性。

在UIDevice擴充類中添加如下代碼

@property (nonatomic , readonly)BOOL isLandscape;@property (nonatomic , readonly)BOOL isPortrait;
-(BOOL)isLandscape{    return UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation);}-(BOOL)isPortrait{    return UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation);}

代碼也可以直接訂閱裝置重新導向通知。為此,可以把beginGeneratingDeviceOrientationNotification發送給currentDevice單例。然後添加一個觀察者,捕獲隨後發生的UIDeviceOrientationDidChangeNotification更新。如你所期望的,可以通過調用UIDeviceOrientationDidChangeNotificationOrientationNotification來完成偵聽。

IOS 特定於裝置的開發:處理基本方向

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.