我“米想尽我同步我的数据库时禁用rightButton在我的导航栏,我子类化的导航栏,因为我需要一点点向上移动的项目。斯威夫特无法使用UINavigationButton 2.2
现在,我尝试在layoutSubviews期间禁用正确的Button。我能够获得UINavigationButton类型的UIView。一旦尝试将UIView强制转换为UINavigationButton,我会收到错误消息:“使用未声明的类型'UINavigationButton'”。所以我想我只需要导入另一个库,但是看起来这个类是不可访问的?或者有人知道要导入什么?
这是我目前的方法,因为我可以读取动态类型并将其转换为字符串,我用它来决定我需要移动哪一个。
let navigationBarItems = self.subviews
var lableInserted = false
var buttons:[UIView] = []
for navigationBarItem in navigationBarItems{
print(String(navigationBarItem.dynamicType))
if String(navigationBarItem.dynamicType) == "_UINavigationBarBackground"{
if syncBarDataSource != nil{
navigationBarItem.frame.origin.y = bounds.origin.y + CGFloat(syncBarDataSource!.barHeight) - CGFloat(maxHeight/2)
navigationBarItem.frame.size.height = bounds.size.height + CGFloat(maxHeight)
} else {
navigationBarItem.frame.origin.y = bounds.origin.y - CGFloat(maxHeight/2)
navigationBarItem.frame.size.height = bounds.size.height + CGFloat(maxHeight)
}
}
if String(navigationBarItem.dynamicType) == "UINavigationButton" || String(navigationBarItem.dynamicType) == "UINavigationItemButtonView"{
buttons.append(navigationBarItem)
}
if let lable = navigationBarItem as? UILabel{
lableInserted = true
lable.text = syncBarDataSource.text
if syncBarDataSource!.barHeight > 0{
lable.hidden = false
} else {
lable.hidden = true
}
}
}
但是,如果我想投像
navigationBarItem as? UINavigationButton
我得到的描述错误
请分享您的代码? –