서브 뷰에서 생성 된 UIImageView의 길게 눌러 제스처가 해당 타겟을 트리거하지 않습니다. 비록 사용자 상호 작용을 이미 활성화했지만 아직 결과가 없습니다. 하위보기가 어떻게 든 방해하여 트리거링을 피합니까? 아니면 완전히 누락 된 것입니까? 커뮤니티에 미리 감사드립니다.스위프트 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