1
これは私のコードです:SwiftのUILongPressGestureRecognizerを使ってindexPath.rowをタグプロパティに渡すには?
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! imageUserCell
let coolGesture = UILongPressGestureRecognizer(target: self, action: #selector(detailedPerson.makeItCoolAction(_:)))
coolGesture.minimumPressDuration = 0.5
coolGesture.view?.tag = 4
cell.addGestureRecognizer(coolGesture)
そして、これは機能コードです:
func makeItCoolAction(sender: UIGestureRecognizer){
print(sender.view?.tag)
print("Photo cooled")
}
コンソール版画同じ値:0、デフォルトの1です。私は強くindexPath.row値をmakeItCoolActionに渡す必要がありますが、UIGestureRecognizerにはタグプロパティはありませんが、.viewプロパティにはコードのように表示されることがあります。
私はmakeItCoolAction送信者をUILongPressGestureRecognizerからUIGestureRecogizerに変更しましたが、依然として0値が出力されています。
あなたが気正しい:あなたはジェスチャーを追加しましたし、それはこのような見解を持っていた後
は、タップを設定してみてください!できます! –