【发布时间】:2015-08-28 14:22:32
【问题描述】:
视图创建:
var myView = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 40))
myView.addSubview(myLabel) // some label
myView.backgroundColor = UIColor.whiteColor()
self.view.addSubview(myView)
var mySwipeGesture = UISwipeGestureRecognizer(target: self, action: "userDidSwipe:")
myView.userInteractionEnabled = true
myView.addGestureRecognizer(mySwipeGesture)
被调用的方法:
func userDidSwipe(sender:UISwipeGestureRecognizer) {
if sender.direction == UISwipeGestureRecognizerDirection.Right {
switchToMain()
}
}
这不起作用,没有调用方法userDidSwipe。
奇怪的是相同的手势识别器mySwipeGesture被添加到另一个UIView(包含许多子视图)并且完美运行!
为什么它不适用于 myView ?我应该检查什么?
【问题讨论】:
-
请显示方法userDidSwipe。
-
要添加到的视图类型是什么?
标签: ios objective-c swift uiview uigesturerecognizer