Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未调用UILabel子类中的UIGestureRecognitor_Ios_Swift_Uigesturerecognizer - Fatal编程技术网

Ios 未调用UILabel子类中的UIGestureRecognitor

Ios 未调用UILabel子类中的UIGestureRecognitor,ios,swift,uigesturerecognizer,Ios,Swift,Uigesturerecognizer,我有一个子类UILabel,看起来像这样: class GestureLabel: UILabel { override init(frame: CGRect) { super.init(frame: frame) initialize() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) initialize(

我有一个子类
UILabel
,看起来像这样:

class GestureLabel: UILabel {

    override init(frame: CGRect) {
        super.init(frame: frame)
        initialize()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        initialize()
    }

    func initialize() {
        self.addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: Selector("longPressGestureRecognizer:")))
    }

    deinit {
        gestureRecognizers?.removeAll()
    }

    func longPressGestureRecognizer(sender: AnyObject) {                
        print("this is never called")
    }
}

但是永远不会调用
LongPressGestureRecognitor
。我做错什么了吗?

默认情况下,
UILabels
上禁用了
userInteractionEnabled
,因此在添加手势识别器时必须手动启用它


确保默认情况下,
UILabels
上禁用了
userInteractionEnabled
,因此在添加手势识别器时必须手动启用它


请确保您将
self.userInteractionEnabled=true

我认为最好将
userInteractionEnabled
默认设置为
false
,以便
UILabel
。是的,这样做有效,我不敢相信我忘记了这一点;)我认为最好提及
UILabel
默认情况下
userInteractionEnabled
false
。是的,这很有效,我不敢相信我忘记了;)