簡體   English   中英

橫向/縱向沖突-iOS

[英]Landscape/Portrait conflict - iOS

就在我以為我想通了一切..我遇到了這個問題。

場景。

我有一個簡單的tableView。 並在導航項的titleView中帶有搜索欄。 SearchBar通過視圖控制器工具欄中的uibarbuttonitem添加到navItems titleView。

現在,通常

用[beginResponder]啟動搜索欄后,鍵盤出現。 然后它發出一個通知“ KeyboardDidShow”,這是我計算UIKeyboard的高度並相應地設置tableView的高度的地方(將其縮短)。

旋轉時-往返風景/肖像時,一切正常。 -(void)didRotateInferfaceOrientation被調用,一切正常。

繼承人的問題。

鍵盤處於活動狀態時,它具有Google“搜索”按鈕,此按鈕會推至新視圖-webviewcontroller。

問題是

何時,[PORTRAIT] ViewController [帶鍵盤處於活動狀態的SearchBar]->點擊搜索-> [Portrait] WebViewController->將設備方向更改為[橫向]-> [橫向] WebViewController更改為橫向--->這里問題,用戶點擊回到uiViewController [Landscape]

不會調用-didRotatefromInterfaceOrientation方法。 並且以某種方式將tableView高度弄亂了。 雖然視圖旋轉完美。

這里有什么我想念的嗎..

將不勝感激。 。謝謝

當用戶點擊時,將不會調用-didRotatefromInterfaceOrientation。 您需要在viewWillAppear中檢查方向(或在從背面輕按返回之前,調用viewDidLoad),然后為所選方向調用正確的布局。

在所有(BOOL)shouldRotate ...方法中,應調用一個單獨的方法以確保布局與設備方向正確。

您可以在viewWillAppear上手動調用didRotateFromInterfaceOrientation,然后自己傳遞一個方向(即[UIApplication sharedApplication] .statusBarOrientation)。

我最近在我的一個應用程序中遇到了類似的問題,不完全是我們的問題,但不要打擾,您應該看到我要去的目標:我想簡單地旋轉一個使用presentModalViewController顯示的viewController ...不幸的是,它沒有確實有效,特別是在iOS 4之前的舊iPhone和OS上。。。所以我需要以編程方式旋轉! 只要獲取您的屏幕尺寸,使用CGAffineTransform或類似的方法並更改尺寸,然后就應該完成了...如果您有興趣,我可以發布一堆代碼,請告訴我!

編輯:

UIScreen *screen = [UIScreen mainScreen];
        myController.view.bounds = CGRectMake(0, 0, screen.bounds.size.height, screen.bounds.size.width - 20);
        if(currentOrientation == UIDeviceOrientationLandscapeRight){
            myController.view.transform = CGAffineTransformConcat(myController.view.transform, CGAffineTransformMakeRotation(degreesToRadian(-90)));

        }else{
            myController.view.transform = CGAffineTransformConcat(myController.view.transform, CGAffineTransformMakeRotation(degreesToRadian(90)));

        }
        myController.view.center = window.center;
        [[UIApplication sharedApplication] setStatusBarOrientation:currentOrientation];
        [self.window addSubview:self.tabBarController.view];
        [self.window bringSubviewToFront:self.tabBarController.view];
        [self.window addSubview:myController.view];
        [self.window bringSubviewToFront:myController.view];
        [self.tabBarController.view removeFromSuperview];`

這還包括在旋轉到橫向時刪除TabBar以獲得更多空間...享受:)

暫無
暫無

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

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