簡體   English   中英

應該AutorotateToInterfaceOrientation不起作用

[英]shouldAutorotateToInterfaceOrientation doesn't work

我一直在以縱向模式編寫我的通用應用程序,現在大約有15個nib文件,許多viewCotnrollers之后,我想實現shouldAutorotateToInterfaceOrientation並在橫向模式下設計一些屏幕。

添加:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 return YES;
} 

到我所有的viewControllers上,不做任何工作。

在調試過程中,我看到此方法被調用,但它根本無法工作! 不在模擬器中,不在設備中,不在Iphone中,不在Ipad中!

我在論壇中搜索了一些答案,並看到一些建議使用:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 return (interfaceOrientation == UIInterfaceOrientationPortrait ||
   interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
   interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
   interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown );
} 

也沒工作

添加:

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

分別對我的viewDidLoad和viewDidUnload都不起作用。

我迷路了。任何幫助都可以!

僅提供一個信息...我所有的View均為UIControl類型,因為我需要TuchUpInside才能工作。

尋求您的幫助。

確保所有父視圖都具有autoresizesSubviews = YES。 如果您尚未在IB中為所有視圖設置彈簧和支柱,則可能需要在代碼中執行此操作。

引用《 Interface Builder用戶指南》:

重要說明:在可可豆粒文件中,如果未在Interface Builder中為視圖設置任何彈簧或撐桿,但是確實使用setAutoresizingMask:方法在運行時添加自動調整大小行為,則您的視圖可能仍未顯示正確的自動調整大小行為。 原因是,如果Interface Builder的子級沒有設置彈簧和撐桿,則它們將完全禁用父級視圖的子級的自動大小調整。 要再次啟用自動調整大小行為,必須將YES傳遞給父視圖的setAutoresizesSubviews:方法。 這樣做后,子視圖應正確自動調整大小。

還有幾件事要注意:

  1. 僅當UINavigationController的根視圖控制器也設置為autorotate時,它才會自動旋轉。

  2. 只有將其所有視圖控制器都設置為自動旋轉時,UITabBarController才會自動旋轉。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    UIInterfaceOrientation des=self.interfaceOrientation;

    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) //iPad
    {
        if(des==UIInterfaceOrientationPortrait||des==UIInterfaceOrientationPortraitUpsideDown)//ipad-portairait
        {

        }
        else//ipad -landscape
        {

        }
    }
    else//iphone
    {
        UIInterfaceOrientation des=self.interfaceOrientation;

        if(des==UIInterfaceOrientationPortrait||des==UIInterfaceOrientationPortraitUpsideDown) //iphone portrait
        {

        }
        else //iphone -landscape
        {

        }
    }
return YES;
}

您要為哪個iOS構建? 在iOS 6.0中已棄用。 (您應該改寫supportedInterfaceOrientations和preferredInterfaceOrientationForPresentation方法。)

您還可以在UIViewController類上調用shouldAutorotate:

https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/shouldAutorotate


確保已在項目設置的“摘要”選項卡中選中了“支持的界面方向”(在頂部的“項目瀏覽器”中選擇項目名稱)。

如果您尚未在此處選擇要使用的方向,則模擬器/ iphone將不允許屏幕更改方向。

我遇到了這個問題,但它在iOS6中有效,但在iOS5中無效。 原來,我在情節提要中有一個視圖,認為我還沒有建立Viewcontroller類。

...最后但並非最不重要的,請確保您沒有激活您的測試設備上(當然,這並不適用於模擬器),這將禁用任何應用旋轉不管什么設置“鎖定縱向” shouldAutorotateToInterfaceOrientation返回。

暫無
暫無

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

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