2016-05-18 21 views
0

Swift for Copy Optionでジェスチャーを長押ししようとしています。Swift、UILongPressGestureRecognizer UIlabelで動作しません

しかし、動作していません。 UiViewまたはUILabelでジェスチャーを識別していません。以下は

私はクラス

0の宣言にすぎUIGestureRecognizerDelegateを追加している私のコード

ビューDidLoadで

 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) 

新優先mothod

func handleLongPress(longPressView :UILongPressGestureRecognizer) { 

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

} 

です

+0

チェックこの回答http://stackoverflow.com/questions/10613118/uilabel-uilongpressgesturerecognizer-not-working?rq=1 – sanman

+0

@sanmanborate、私はすでにそれを行っています..しかし、動作していません.. self.lblDynaMobile.userInteractionEnabled = true –

+0

@dhavalshah、この答えを確認してくださいhttp://stackoverflow.com/questions/13929703/why-does-uitableviews-swipe-delete-sometimes-work -fine-sometimes-not/20157326#20157326 – bademi

答えて

0

(それが働いている。)これを試してみて、そして見

// in viewDidLoad() 
let copyLongPress = UILongPressGestureRecognizer(target: self, action: #selector(self.handleLongPress(_:))) 
self.lblDynaMobile.addGestureRecognizer(copyLongPress) 

func handleLongPress(_ gesture: UILongPressGestureRecognizer) { 

    if let lblFont = gesture.view as? UILabel { 
     //UIPasteboard.generalPasteboard().string = lblFont.text 
    } 

} 
関連する問題