[英]How to Flip a view (with UIModalTransitionStyleFlipHorizontal) inside UINavigationController and UITabBarController
[英]How to force horizontal orientation for a view inside of a UITabBarController?
我的 MainWindow.xib 中有一個 UITabBarController。
每個選項卡都包含一個 UINavigationController,它有一個 UITableViewController。
當我按下 UITableViewController 中的按鈕時,我想將視圖 controller 以水平方向推送到導航堆棧上。
我在 UITableViewController 中覆蓋了以下內容
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return YES;
}
但是推送的視圖 controller 不會出現在水平方向(在 XIB 中它被定義為橫向)。
如何在水平方向推動它?
UITabBarController
和UINavigationController
的自動旋轉有一些限制:
對於 UITabBarController,只有當標簽欄中的所有控制器都支持自動旋轉時,自動旋轉才會起作用;
對於 UINavigationController,僅當 UINavigationController 中的 rootViewController 支持時,自動旋轉才會起作用。
一旦你確保滿足這個條件,那么你可以嘗試推動你的 UITableViewController 已經定義了它的 shouldAutorotateToInterfaceOrientation ,如下所示:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLanscape);
}
編輯:
你所有的 UIViewControllers 都應該有這個shouldAutorotateToInterfaceOrientation
的定義:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
除了你想強制橫向的那個,它應該有上面給出的定義。
還請查看此線程中的最后一篇文章,以正確實現 UITabBarController 的 shouldAutorotateToInterfaceOrientation。
您需要在 viewWillAppear 方法中更改狀態欄方向並在 viewWillDisappear 等中恢復。在方法中也只返回橫向
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (UIInterfaceOrientationLandscapeRight or UIInterfaceOrientationLandscapeLeft);
}
你的方法似乎合乎邏輯。 但是,您是否在只想成為橫向的推送視圖 controller 中嘗試過這個:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
此方法的想法是為您支持的視圖 controller 的方向返回 YES。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.