Getting the frame of a particular tab bar item

前端 未结 12 1018
礼貌的吻别
礼貌的吻别 2021-02-02 07:42

Is there a way to find the frame of a particular UITabBarItem in a UITabBar?

Specifically, I want to create an animation of an image \"falling\

12条回答
  •  死守一世寂寞
    2021-02-02 08:06

    You do not need any private API, just use the UITabbar property itemWidth and itemSpacing. Set these two values like following:

    NSInteger tabBar.itemSpacing = 10; tabBar.itemWidth = ([UIScreen mainScreen].bounds.size.width - self.tabBarController.tabBar.itemSpacing * (itemsCount - 1)) /itemsCount;

    Note this will not impact the size or position of image and title used for UITabBarItem.

    And then you can get the ith item's center x like following:

    CGFloat itemCenterX = (tabBar.itemWidth + tabBar.itemSpacing) * ith + tabBar.itemWidth / 2;

提交回复
热议问题