0

コピーオプションのSwiftでジェスチャを長押ししようとしています。

しかし、それは機能していません。UiView または UILabel でジェスチャーを識別していません。

以下は私のコードです

ビューで

     let copyLongPress = UILongPressGestureRecognizer(target: self, action: #selector(ContactDetailController.handleLongPress(_:)))
    copyLongPress.numberOfTouchesRequired = 0
    copyLongPress.delegate = self
    copyLongPress.minimumPressDuration=0.5
    self.lblDynaMobile.addGestureRecognizer(copyLongPress)
    self.lblDynaMobile.userInteractionEnabled = true
    self.lblDynaDDI.addGestureRecognizer(copyLongPress)
     self.lblDynaDDI.userInteractionEnabled = true
    self.GeneralView.addGestureRecognizer(copyLongPress)
    self.EmailView.addGestureRecognizer(copyLongPress)
    self.AddressView.addGestureRecognizer(copyLongPress) 

新しい方法

func handleLongPress(longPressView :UILongPressGestureRecognizer) {

    let lblFont:UILabel = (longPressView.view as? UILabel)!
    UIPasteboard.generalPasteboard().string = lblFont.text

}

クラスの宣言に UIGestureRecognizerDelegate も追加しました

4

1 に答える 1