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