【发布时间】:2023-03-16 03:50:02
【问题描述】:
手势识别器不起作用。
执行下面元素的动作。
我将 UIView 添加到 TabBarController。
如果我点击创建的 UIView,它下面的元素的动作就会被执行。
class func createSpeechView(tabBar: UITabBarController)
{
let speech = Bundle.main.loadNibNamed("Speech", owner: Bundle.main, options: nil)![0] as! SpeechView
tabBar.tabBar.addSubview(speech)
speech.translatesAutoresizingMaskIntoConstraints = false
speech.centerXAnchor.constraint(equalTo: tabBar.tabBar.centerXAnchor).isActive = true
speech.topAnchor.constraint(equalTo: tabBar.tabBar.topAnchor, constant: -(height + 10)).isActive = true
speech.widthAnchor.constraint(equalTo: tabBar.tabBar.widthAnchor, multiplier: 1.0, constant: -30).isActive = true
speech.heightAnchor.constraint(equalToConstant: height).isActive = true
speech.isUserInteractionEnabled = true
speech.addGestureRecognizer(UIGestureRecognizer(target: tabBar, action: #selector(tapGesture)))
}
@objc class func tapGesture()
{
print("tap")
}
例子:
【问题讨论】:
-
使用 UITapGestureRecognizer
标签: swift xcode swift3 uiview uigesturerecognizer