-1

このチュートリアルに従って、iPhone の UITabBar に素敵な矢印ができました。

iPadでも同じことをしたかったのですが、うまくいかないようです。

私は試した

- (CGFloat) horizontalLocationFor:(NSUInteger)tabIndex
{   
    CGFloat tabItemWidth;
    CGFloat halfTabItemWidth;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        tabItemWidth = 320 / tabBarController.tabBar.items.count;
        halfTabItemWidth = (tabItemWidth / 2.0) - (tabBarArrow.frame.size.width / 2.0);
    }
    else 
    {
        tabItemWidth = 768 / tabBarController.tabBar.items.count;
        halfTabItemWidth = (tabItemWidth / 2) - (tabBarArrow.frame.size.width / 2);
    }

    return (tabIndex * tabItemWidth) + halfTabItemWidth;
}

例に従って、iPad の tabBar の寸法を取りますが、矢印はまだ各タブの中央にはありません。

何か助けはありますか?

4

1 に答える 1

1

あなたが持っている現在の「horizo​​ntalLocationFor」メソッドの代わりにこれを試してください:

- (CGFloat) horizontalLocationFor:(NSUInteger)tabIndex
{
    // Get the frame of the selected tab item's view.
    // Add one becuase the first subview is the not a button.
    CGRect tabFrame = [[[[[self tabBarController] tabBar] subviews] objectAtIndex:tabIndex+1] frame];

    // Add tab x to half tab width and substract hald arrow image width to center it.
    return tabFrame.origin.x + (tabFrame.size.width * .5) - (tabBarArrow.frame.size.width * .5);
}

元の解決策では、タブ バーの幅が画面全体であると想定していましたが、iPad 4 の項目はタブ バーの幅の一部しか占めていないため、幅を項目の数で割っても正しい位置が得られません。

于 2012-07-11T14:45:44.777 に答える