2012-03-08 113 views
0

你好,我想在我的應用程序中支持肖像,主頁按鈕,我該怎麼做?支持方向IOS

我去我的項目設置,檢查這兩個enter image description here

,我在下面添加

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

我也試過

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

的代碼,但沒有一個似乎工作

任何幫助

+0

您確定將代碼放在正確的控制器中嗎?你是否嘗試過只是返回YES來查看它是否是邏輯問題(即使它看起來不錯)? – 2012-03-08 22:14:26

+0

一切都是正確的,但是...你把那些代碼放在哪裏?在哪個控制器上? – fbernardo 2012-03-08 22:16:01

+0

是的我有一個視圖控制器,它在那裏我試過也是,這也不工作要麼 – 2012-03-08 22:16:26

回答

2

試試這個

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ 
    if((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){ 
     return YES; 
    } 
    return NO; 
} 

如果還是不行,可以試試這個(只是爲了測試的緣故)

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

如果這不起作用,要麼你是不是搞亂了正確的視圖控制器,或者父/根視圖控制器禁用了旋轉(在rootVC的shouldAutoRotate方法中返回NO)

+2

你不說... – fbernardo 2012-03-08 22:22:15

+1

@fbernardo已經建議,OP說它不適合他。 – sch 2012-03-08 22:43:05

+0

好吧,它不得不把我的代碼放在每一個視圖中,因爲這是在一個標籤欄控制器非常感謝您的幫助 – 2012-03-08 22:46:29