@IBOutlet var topView: UIView
@IBOutlet var bottomView: UIView
在storyboard中启用了topView和bottomView中的userInteractionEnabled
这是我在ViewController.swift中的代码
override func viewDidLoad() {
super.viewDidLoad()
var tap = UITapGestureRecognizer(target: self, action: "tapTheView:")
self.topView.addGestureRecognizer(tap)
self.bottomView.addGestureRecognizer(tap)
}
这是UITapGestureRecognizer的方法
func tapTheView(recognizer: UITapGestureRecognizer) {
println("Hi")
}
但当我点击topView时没有发生任何事情,当我点击底部查看我的应用程序崩溃并在此行中显示主题1:EXC_BAC_ACESS
class AppDelegate: UIResponder, UIApplicationDelegate {
我正在使用Xcode 6 beta 2。
当我在XCode 5.1.1中使用上面相同的代码(但使用objective-c)尝试它时,它可以工作。非常感谢你,抱歉我的英语不好
答案 0 :(得分:2)
这在Xcode beta 2中没有崩溃。有一点是你必须为每个视图Check this link添加单独的手势。即
var tap = UITapGestureRecognizer(target: self, action: "tapTheView:")
self.topView.addGestureRecognizer(tap)
var tap2 = UITapGestureRecognizer(target: self, action: "tapTheView:")
self.bottomView.addGestureRecognizer(tap2)