0
在子视图上创建的UIImageView上的长按手势不会触发其目标。虽然,我已经启用了用户交互,但没有结果。 子视图以某种方式干涉和避免触发或我完全失去了一些东西? 我向社区提前致谢。Swift 3长按手势无法在子视图上工作
private func createShieldView() -> Void {
self.baseView.addSubview(self.imageForShield)
self.imageForShield.translatesAutoresizingMaskIntoConstraints = false
//Constraints functions created in an extension
self.imageForShield.horizontalLeft(toItem: self.alarmBaseView, constant: 0)
self.imageForShield.horizontalRight(toItem: self.alarmBaseView, constant: 0)
self.imageForShield.topConstraints(toItem: self.labelForInstruction, constant: 5, toBottomOf: true)
self.imageForShield.heightConstriants(constant: 250)
let imageFile = UIImage(named: "stateInactive")
self.imageForShield.image = imageFile
self.imageForShield.contentMode = UIViewContentMode.scaleAspectFit
self.imageForShield.tag = tagsAssignedToViews.shieldView.rawValue
let longPressEvent = UILongPressGestureRecognizer(target: self, action: #selector(ViewController._selectorLongPressEvent(longPressGestuer:)))
longPressEvent.minimumPressDuration = 2.0
self.imageForShield.addGestureRecognizer(longPressEvent)
self.imageForShield.isUserInteractionEnabled = true
}
//In ViewController.swift
public func _selectorLongPressEvent(longPressGestuer: UILongPressGestureRecognizer) -> Void {
if longPressGestuer.state == UIGestureRecognizerState.began {
print("Long press event triggered")
}
}
@mitul marsonia,谢谢,但没有工作。 – Odd