【问题标题】:Hiding UITabBar when rotating device iPhone旋转设备 iPhone 时隐藏 UITabBar
【发布时间】:2010-02-18 10:05:29
【问题描述】:

是否有人在旋转设备时成功隐藏了 UITabbar?

我在 UItabbar 控制器中有一个可以旋转的视图(所以实际上是一个可以旋转的选项卡)

发生这种情况时,我希望标签栏消失...但似乎没有任何效果!

标签栏仍然可见

或者它随着视图一起消失

或者标签栏消失,视图不再旋转!

因此,如果有人成功完成了这项任务,任何建议都将不胜感激!

谢谢

汤姆

【问题讨论】:

  • 您是否尝试过在设备旋转时显示 modalViewController 以使其不属于 TabBarController 的一部分?
  • 这对我不起作用,因为我正在显示一个 webview ......所以如果我这样做,这将意味着在旋转时重新加载 webview

标签: iphone uitabbarcontroller rotation uitabbar


【解决方案1】:

抱歉 pk 回复晚了

我设法旋转并隐藏了标签栏。

首先它是 UITabBarController 的子类化,并包含这个方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    //This allows us to get the rotation calls from any view in the tab bar
    // 

    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation];
}

然后您可以只从所需的视图控制器旋转。

隐藏标签栏:

获取应用委托和标签栏控制器的引用,然后将标签栏设置为隐藏:

MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
UIView *tabBar = [delegate.tabBarController.view.subviews objectAtIndex:1];
tabBar.hidden = TRUE;

希望这会有所帮助!

【讨论】:

    【解决方案2】:

    您是否尝试在视图控制器中的 UIDeviceOrientationDidChangeNotification 通知上添加观察者,并对此回调执行“隐藏 = true 或 false”?

    我使用 MonoTouch 框架通过以下 C# 代码成功实现了这一点。

    void Initialize ()
    {
        NSNotificationCenter.DefaultCenter.AddObserver("UIDeviceOrientationDidChangeNotification", DeviceRotated);          
    }
    
    private void DeviceRotated(NSNotification notification)
    {
        if ( notification.Name.Equals("UIDeviceOrientationDidChangeNotification") )
        {
            Console.WriteLine(UIDevice.CurrentDevice.Orientation.ToString());
            if ( UIDevice.CurrentDevice.Orientation != UIDeviceOrientation.Portrait ) 
            {
                tabBar.Hidden = true;
                //Plus some additional logic.
            }
            else
            {
                tabBar.Hidden = false;
            }
        }
    }
    

    【讨论】:

    • 你应该把它放在你希望发生旋转通知的视图的 ViewController 中。
    【解决方案3】:

    你真的可以在 UItabbarController 中隐藏标签栏吗?至少笔尖不允许您从底部栏下拉菜单中选择无。

    【讨论】:

      猜你喜欢
      • 2010-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多