![](/img/trans.png)
[英]IOS : Tabbar item click again and again it is double Tab bar button item size
[英]IOS:UITabbar item click again and again it is reducing the UITabbar button item size in IOS 7
我在這里拿了Tabbar viewcontroller,我添加了5項和.I給出了圖像昆蟲是(24,0,0,6)。 所有按鈕圖像都添加在xib [條形項目 - >圖像下]請幫忙。 謝謝。
在這里添加類似的答案: iOS Tab Bar圖標不斷變大
不確定這是否是iOS7錯誤,但我注意到圖像插入需要平衡。
您已為頂部和右側指定了插入但是:
因此,不要使用像(24,0,0,6)
這樣的圖像插入,而是使用平衡圖像插入,例如UIEdgeInsetsMake(24,-6,-24,6)
這樣做可以保護您的tabBarItem
圖像不會在每次點擊時受到打擊。
如果這不符合您的要求,那么重新設計您的tabBarItem
圖像,這樣您就可以擁有平衡插圖或者根本沒有插入內容。
這是我在UITabBarController
的UITabBar
遇到的錯誤的解決方法。 如果我在選擇UITabBarItem
之后點擊一次,則圖標會縮小。 我想做的是禁用觸摸。 UITabBarItem
只有一個isEnabled
的設置,如果我將它設置為false
,它會變灰...不是我想要的。
我用這個答案的衍生物來弄明白。 用UITabBarController
有3個標簽,印刷tabBarController.subviews
,只見3個UITabBarButtons
和UIBarBackground
。 UIBarBackground框架的原點總是(0, 0)
,把它放在排序數組的前面,所以我真的不需要知道子視圖是什么,只是“它在哪里”以及它是否總是在那里。 該UIBarBackground
總是會處於數組的前tabBarController.subviews
排序frame.minX
,所以我只需要拆掉它。
這是擴展的樣子:
extension UITabBarController {
var buttonViews: [UIView] {
var tabBarButtons = tabBar.subviews.sorted(by: {$0.frame.minX < $1.frame.minX})
tabBarButtons.removeFirst()
return tabBarButtons
}
}
我還在Constants文件中創建了一個struct
,所以我不必記住選項卡名稱:
struct TabBarItem {
static let firstTab = 0
static let secondTab = 1
static let thirdTab = 2
}
......最后,在哪里使用它:
在viewDidAppear
(NOT viewDidLoad
)中,添加以下行以禁用您不想禁用但不灰顯的UITabBarItem
:
tabBarController?.buttonViews[TabBarItem.firstTab].isUserInteractionEnabled = false
在viewWillDisappear
,重新啟用選項卡,如下所示:
tabBarController?.buttonViews[TabBarItem.firstTab].isUserInteractionEnabled = true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.