2016-09-29 12 views
0

がある場合、テキストの色を変更するつもりはない私持って、次のコード:UIButtonは、長押しジェスチャー認識

deleteAllButton.setTitle("Delete", forState: .Normal) 
     deleteAllButton.titleLabel?.numberOfLines = 2 
     deleteAllButton.setTitleColor(UIColor.blackColor(), forState: .Normal) 
     deleteAllButton.titleLabel?.font = UIFont.systemFontOfSize(keyboardFontSize) 
    // deleteAllButton.addTarget(self, action: #selector(deletekeyPressed), forControlEvents: .TouchUpInside) 

     let deleteLPGR = UILongPressGestureRecognizer(target: self, action: #selector(deleteButtonLongPress)) 
     deleteLPGR.minimumPressDuration = 0 
     deleteLPGR.delaysTouchesBegan = true 

     deleteAllButton.addGestureRecognizer(deleteLPGR) 
UIButtonがテキストを押すと通常

自動的に「プレス」であることを示すために色が変化状態。しかし、長押しのジェスチャ認識機能を追加しているため、ボタンは「押した」状態であることを示していません。

タッチイベントがボタンに届くようにするには、どうすればボタンが実際に「押し込まれた」ように感じることができますか?

答えて

0

ジェスチャ認識機能を追加する必要はありません。

だけhighlited状態のためtitlecolorを設定しようと、それは

deleteAllButton.setTitleColor(UIColor.redColor(), forState: .Highlighted) 

を動作するはずですが、これはあなたの問題を解決することを願っています。

0

deleteLPGR.minimumPressDuration = 0からdeleteLPGR.minimumPressDuration = 1に変更すると、

を押すと色の変化がわかります
関連する問題