简体   繁体   中英

UITabBarController icons changing height on touch

I have an issue with UITabBarController , the icons are changing size if I keep my finger on them and drag up or down, they are losing height by my dragging action, how can I stop that?

Here is my code:

override func viewWillAppear(_ animated: Bool) {
   .................

    vc_friends.tabBarItem.imageInsets   = UIEdgeInsets(top: 6, left: 0, bottom: -5, right: 0)
    vc_topCharts.tabBarItem.imageInsets = UIEdgeInsets(top: 6, left: 0, bottom: -5, right: 0)
    vc_newsfeed.tabBarItem.imageInsets  = UIEdgeInsets(top: 6, left: 0, bottom: -5, right: 0)
    vc_myProfile.tabBarItem.imageInsets = UIEdgeInsets(top: 6, left: 0, bottom: -5, right: 0)
    vc_pools.tabBarItem.imageInsets     = UIEdgeInsets(top: 6, left: 0, bottom: -5, right: 0)

    self.viewControllers = [vc_friends,vc_topCharts,vc_newsfeed,vc_pools,vc_myProfile]

    self.selectedIndex = 2
}

This is how it looks like:

正确显示的标签栏项目

...and this if I click on it and keep my finger on it and move my finger up or down:

标签栏项目扭曲

This is a known issue when your negative value is not the opposite of the positive value in the other direction. Change your insets to this:

UIEdgeInsets(top: 6, left: 0, bottom: -6, right: 0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM