簡體   English   中英

檢測lanscap模式並顯示UIImage

[英]Detect the lanscap mode and show an UIImage

我正在開發僅使用縱向模式的iOS應用程序。 我想在用戶轉動iPhone(橫向模式)時在我的應用程序的所有視圖中顯示圖像(320 * 480)

我該怎么做?

您可以在UIViewController方法didRotateFromInterfaceOrientation:完成此操作,該方法將在用戶旋轉設備后立即調用。

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    if (self.interfaceOrientation != UIInterfaceOrientationPortrait) {
        // add image to self.view
    } else {
        // remove image from self.view
    }
}

您可以在每個應用程序的視圖控制器中實現此方法。 或者,您可以在UIViewController的自定義子類中實現此功能,然后讓所有應用程序的視圖控制器都從自定義視圖控制器繼承。

編輯

正如@David Dunham所建議的那樣,如果您要做的就是阻止應用程序在用戶旋轉設備時更改方向,則可以通過實現UIViewController方法shouldAutorotateToInterfaceOrientation:輕松實現。 對於您要支持的每個方向,該方法都應返回YES ,而對於不希望支持的任何方向,則返回NO

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // only allow portrait orientation
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

shouldAutorotateToInterfaceOrientation:返回NO會更容易嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM