Getting the frame of a particular tab bar item

前端 未结 12 1021
礼貌的吻别
礼貌的吻别 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 07:58

    Swift 5:

    Just put this in your View Controller that handles your tabBar.

    guard let tab1frame = self.tabBar.items![0].value(forKey: "view") as? UIView else {return}
    

    then use like so:

    let tab1CentreXanc = tab1frame.centerXAnchor
    let tab1CentreY = tab1frame.centerYAnchor
    let tab1FRAME = tab1frame (centerX and Y and other parameters such as ".origins.x or y"
    

    Hope that helps.

    If you want to reference the parameters from other tabs, just change the index from [0] to whatever you want

提交回复
热议问题