Center X Coordinate of TabBarItem

时间:2018-07-25 04:38:25

标签: ios swift

I am trying to get the center x coordinate of the selected tab bar item. I have managed to get the selected index, however I am struggling to figure out how to get the selected TabBarItem's frame and center x coordinate. Any help is much appreciated.

Thanks.

EDIT

I ended up solving my issue mathematically. See my solution below:

//viewControllers refers to the array of ViewControllers controlled by the Tab Bar    
let tabSize = tabBar.frame.size.width / CGFloat((viewControllers?.count)!)
let tabBarStart = tabBar.frame.origin.x

let targetX = tabBarStart + (tabSize * index) + (tabSize / 2)

0 个答案:

没有答案