iOS 6 手持方向處理

來源:互聯網
上載者:User

iOS6手持方向處理
從iOS 5的應用程式更新到iOS6很多特性沒法正常工作。主要的問題是,有一些API在新的SDK中已被棄用。其中手持方向的判斷就是很明顯的一個

存在的問題
假如你應用程式只有一個屏要是橫向,其它的屏都要是縱向。

iOS 5的解決方案
在應用程式的Info.plist檔案,Supported interface orientations應該只包含一個項目,Portrait 。

接下來,在需要的方向鎖定為橫向視圖控制器類,你需要重寫- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation方法,並返回YES或NO相對一個布爾值,檢查對interfaceOrientation參數。

下面是函數看起來像什麼。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
iOS的6解決方案
在iOS 6 -(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 方法已淘汰,似乎沒有被調用了。代替它的一組方法;-(BOOL)shouldAutorotate 和-(NSUInteger)supportedInterfaceOrientations的。

在UIViewController,你要在橫向的,你需要同時重寫- (BOOL)shouldAutorotate- (NSUInteger)supportedInterfaceOrientations的:

// iOS6中過時, 為了相容iOS5.
// ---
- (BOOL)shouldAutorotateToInterfaceOrientation:
        (UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

// iOS6 support
// ---
- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}
// ---

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.