UITabBarController图标在触摸时改变高度

问题描述 投票:0回答:1

我有UITabBarController的问题,如果我把手指放在它们上面并向上或向下拖动,图标会改变尺寸,它们会因拖动动作而失去高度,我怎么能阻止它?

这是我的代码:

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
}

这是它的样子:

correctly displayed tab bar item

......如果我点击它并将手指放在上面并向上或向下移动我的手指:

distorted tab bar item

ios uitabbar uitabbaritem uiedgeinsets
1个回答
2
投票

当您的负值与另一个方向的正值不相反时,这是一个已知问题。将你的插图更改为:

UIEdgeInsets(top: 6, left: 0, bottom: -6, right: 0)
© www.soinside.com 2019 - 2024. All rights reserved.