Getting the frame of a particular tab bar item

前端 未结 12 1040
礼貌的吻别
礼貌的吻别 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:57

    By Extending UITabBar

    extension UITabBar {
    
        func getFrameForTabAt(index: Int) -> CGRect? {
            var frames = self.subviews.compactMap { return $0 is UIControl ? $0.frame : nil }
            frames.sort { $0.origin.x < $1.origin.x }
            return frames[safe: index]
        }
    
    }
    
    extension Collection {
    
        subscript (safe index: Index) -> Element? {
            return indices.contains(index) ? self[index] : nil
        }
    
    }
    

提交回复
热议问题