我手动添加了一个标签栏来查看控制器,这不是tabBarController
,因为我只希望标签栏UI,而不是标签栏功能
我想单击标签栏并显示新的ViewController
,但是我无法在storyBoard
中这样做
如果我使用此方法,则xcode会提示我Value of type 'UITabBarItem' has no member 'isUserInteractionEnabled'
和Value of type 'UITabBarItem' has no member 'addGestureRecognizer'
如何单击UITabBarItem?
How to make a UILabel clickable?
@IBOutlet weak var setting: UITabBarItem!
@IBOutlet weak var activity: UITabBarItem!
@IBOutlet weak var profile: UITabBarItem!
@IBOutlet weak var connect: UITabBarItem!
@IBOutlet weak var scanner: UITabBarItem!
override func viewDidLoad() {
super.viewDidLoad()
let tap = UITapGestureRecognizer(target: self, action: #selector(tapFunction))
setting.isUserInteractionEnabled = true
setting.addGestureRecognizer(tap)
activity.isUserInteractionEnabled = true
activity.addGestureRecognizer(tap)
profile.isUserInteractionEnabled = true
profile.addGestureRecognizer(tap)
connect.isUserInteractionEnabled = true
connect.addGestureRecognizer(tap)
scanner.isUserInteractionEnabled = true
scanner.addGestureRecognizer(tap)
}
@objc func tapFunction(sender:UITapGestureRecognizer) {
print("tap working")
}
答案 0 :(得分:1)
类型'UITabBarItem'的值没有成员'isUserInteractionEnabled',类型'UITabBarItem'的值没有成员'addGestureRecognizer'
由于UITabBarItem继承自UIBarItem,而UIBarItem继承自NSObject,而不是UIView
要启用/禁用
UITabBarItem
,可以使用isEnabled
属性
https://developer.apple.com/documentation/uikit/uibaritem/1616418-isenabled?changes=_2
要捕获
中捕获它。UITabBarItem
的动作,可以在UITabBar的委托tabbar:didselectitem
https://developer.apple.com/documentation/uikit/uitabbardelegate/1623463-tabbar?changes=_2
,并通过UITabBarItem.tag
获得了商品的位置
https://developer.apple.com/documentation/uikit/uibaritem/1616419-tag?changes=_2