提升中心UITabBar按钮和横向模式?

时间:2011-03-11 22:45:35

标签: iphone

iDevRecipes有一些代码允许提升中心标签栏按钮。

http://idevrecipes.com/2010/12/16/raised-center-tab-bar-button/

他们在那里提到的应用程序(Path,Instagram等)都只限于纵向视图。

如何处理横向模式中的凸起按钮以及默认的纵向?

我在TabBar派生类中添加了shouldAutoRotate,但并非所有这些都是必需的。

1 个答案:

答案 0 :(得分:0)

据我所知,在景观中使用它应该没有任何问题。当然我没有尝试过代码,所以我不能做出任何承诺。

我想象你遇到的问题是旋转后中心按钮没有居中。我想最简单的解决方法是使用以下代码

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    CGFloat heightDifference = buttonImage.size.height - self.tabBar.frame.size.height;
    if (heightDifference < 0) {
        button.center = self.tabBar.center;
    } else {
        CGPoint center = self.tabBar.center;
        center.y = center.y - heightDifference/2.0;
        button.center = center;
    }
}

上面的代码假设button是一个实例变量。

我想如果你想做一些更有趣的事情,你应该覆盖以下方法:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

并为按钮的居中设置动画,但我不会为此提供代码。

我没有运行我提供的代码,但我认为它应该可行。如果没有,请发表评论,我会看到我可以做些什么来改进它。