2012-04-17 54 views
1

我搜索了每一個地方,但沒有找到解決方案這是我在iPhone新。在每一個我得到的設置導航的高度或我的看法是不旋轉的方向像issue.my視圖是旋轉,但我的導航欄是在相同的位置,請有人幫助我,如果你有解決方案。感謝我顯示了一些代碼在我用於Orientation.When我點擊我的標籤欄我的模擬器是自動旋轉,我希望製表符酒吧也旋轉,但使用此代碼只模擬器旋轉不是標籤欄和導航欄,並抱歉我的英語不好。導航欄問題的方向

CGAffineTransform transform = CGAffineTransformIdentity; 

switch ([[UIApplication sharedApplication] statusBarOrientation]) 
{ 

    case UIInterfaceOrientationPortrait: 
     transform = CGAffineTransformMakeRotation(M_PI_2); 
     break; 

    default: 
     break; 
} 

[[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationPortrait]; 

[UIView animateWithDuration:0.2f animations:^ { 

    [self.navigationController.view setTransform:transform]; 

}]; 

[self.view setFrame:CGRectMake(0, 0, 320, 480)]; 
[self.view setNeedsLayout]; 
+0

導航欄自動旋轉。當方向改變時。並提交你的這行// [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; ...嘗試它 – Ayaz 2012-04-17 13:28:36

+0

@Ayaz謝謝但這種解決方案是不工作在我的代碼它停止我的自動模擬器orientation.I只是想旋轉導航欄旋轉我的看法已經旋轉,如果你有解決方案幫助我哥們非常感謝你 – vishiphone 2012-04-18 03:52:04

回答

1

此代碼沒有違規意圖,非常好奇。我不確定你想要做什麼。你想解決什麼問題?玩CGAffineTransform的遊戲肯定會產生奇怪的結果,就像你描述的那樣,如果你不是很小心。

如果您只是想確保您的應用成功支持橫向和縱向,您可以在視圖控制器中實現shouldAutorotateToInterfaceOrientation。當你這樣做時,所有的各種控制都會相應地重新定位自己。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Support all orientations on iPad 
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
     return YES; 

    // otherwise, for iPhone, support portrait and landscape left and right 

    return ((interfaceOrientation == UIInterfaceOrientationPortrait) || 
     (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
     (interfaceOrientation == UIInterfaceOrientationLandscapeRight)); 
} 

但是,如果我誤解你想要做什麼,即你正在試圖做的事情不僅僅是同時支持橫向和縱向更復雜,讓我知道。


我很抱歉,因爲我不記得你在那裏我本來得到這個代碼(但它在SO here提及),但可用於強制橫向如下:

首先,確保您應該shouldAutoRotateToInterfaceOrientation內容如下:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
     (interfaceOrientation == UIInterfaceOrientationLandscapeRight)) 
     return YES; 
    else 
     return NO; 
} 

其次,在viewDidLoad中,添加以下代碼:

if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) 
{ 
    UIWindow *window = [[UIApplication sharedApplication] keyWindow]; 
    UIView *view = [window.subviews objectAtIndex:0]; 
    [view removeFromSuperview]; 
    [window addSubview:view]; 
} 

出於某種原因,從主窗口中刪除視圖,然後重新添加它迫使它查詢shouldAutorotateToInterfaceOrientation並正確設置方向。鑑於這不是蘋果認可的方法,也許應該避免使用它,但它適用於我。你的旅費可能會改變。但是that SO discussion也指其他技術。

+0

謝謝它的工作正常,但一個錯誤,它只顯示一次,當我們先移動到後面的屏幕後,如果我們再次移動到該屏幕,它將無法正常工作我發佈你的代碼在視圖也appair也,但它有同樣的問題,但我試圖解決那直到現在。 – vishiphone 2012-04-18 05:22:18