![](/img/trans.png)
[英]Tabbar's viewcontroller gets reload while changing the orientation, in iOS 8
[英]iOS app - changing the orientation in tabbar
在我的應用程序中,我有一個帶有5個按鈕的標簽欄。 整個應用程序只有縱向,我已經正確設置了。
我的問題是,當我單擊選項卡的第二個按鈕時,視圖通常以縱向顯示,但是當用戶傾斜設備時,我希望將該特定視圖更改為橫向。 是否可以將標簽欄的位置更改為橫向,並且單擊其他按鈕全部都更改為縱向?
另外,當它傾斜時,我必須在沒有選項卡的情況下單獨顯示風景,該怎么辦?
試試這個wrt: tabbar.selectedViewController
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeRight];
因此,為了清楚起見,您希望整個應用程序以及所有縱向視圖(除了由第二個標簽欄按鈕觸發的視圖之外,都希望始終以橫向顯示)?
如果我沒有混淆您的問題,則只需將以下代碼行放在第2個視圖的控制器的“ viewDidLoad”方法中
self.view.transform = CGAffineTransformMakeRotation(M_PI / 2);
您可能想要硬着頭皮,讓您的項目在其最高級別接受多個方向,然后根據每個UIViewController決定支持哪些方向。 這將使框架能夠為您完成很多工作(總是一個好主意)。
在每個視圖的控制器中,重寫此方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
對於您要視圖支持的任何方向,您將希望返回YES
。
interfaceOrientation參數的四個選項是:
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
因此,對於您的情況,您將希望托管視圖和選項卡欄的視圖控制器支持所有方向。 該函數的外觀如下:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return YES;
}
但是,要獲得更多細節,如果您只想支持“橫向左”和“縱向顛倒”方向,則該函數應如下所示:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
如果所有選項卡的ViewControllers在shouldAutorotateToInterfaceOrientation處返回YES,則UITabBar僅支持旋轉。
如果讓“人像”標簽檢查是否可見,則可以實現所需的目標(通過
tabbar.selectedViewController
或tabbar.selectedIndex
並且僅在未選中它們時回答“是”。
但是,當用戶在橫向模式下更改選項卡時,會呈現縱向視圖,從而使用戶體驗感到困惑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.