逻辑问题:即使用户平移过一次,如何让单元格图像继续翻转?

问题描述

目标:用户在集合视图上平移时,当前单元格中的图像翻转一次。如果用户再次平移该图像(即使在相同的连续触摸中),图像将再次翻转。

What it should be doing

问题:用户在图像上平移一次后,图像将不再翻转,无论是相同的触摸还是新的触摸。我知道这是一个逻辑问题。只是不确定如何正确操作这里的控制流......非常感谢任何人对此进行破解!

What it's doing

class GameTileCVC: UICollectionViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    
    collectionView.backgroundColor = .black
    self.collectionView!.register(GameTileCell.self,forCellWithReuseIdentifier: GameTileCell.reuseID)
    addPan()
}


func addPan() {
    let pan = UIPanGestureRecognizer(target: self,action: #selector(handlePan(sender:)))
    view.addGestureRecognizer(pan)
    collectionView.addGestureRecognizer(pan)
}


@objc func handlePan(sender: UIPanGestureRecognizer) {
    if let indexPath = self.collectionView?.indexPathForItem(at: sender.location(in: self.collectionView)) {
        let cell = collectionView?.cellForItem(at: indexPath) as! GameTileCell
        let location = sender.location(in: collectionView)
        
        switch sender.state {
        case .began,.changed,.ended:
            if cell.frame.contains(location) && !cell.hasBeenFlipped {
                flip(sender: sender,cell: cell)    // hasBeenFlipped = true
            }
        default:
            break
        }
    }
}


func flip(sender: UIPanGestureRecognizer,view: GameTileCell) {
    let direction = sender.direction(in: collectionView)
    if direction.contains(.Right) {
        UIView.transition(with: view.gameTileImageView,duration: 0.5,options: .transitionFlipFromLeft) {
            self.setimageAndColor(for: view)
        }
    } else if direction.contains(.Left) {
        UIView.transition(with: view.gameTileImageView,options: .transitionFlipFromright) {
            self.setimageAndColor(for: view)
        }
    } else if direction.contains(.Up) {
        UIView.transition(with: view.gameTileImageView,options: .transitionFlipFromTop) {
            self.setimageAndColor(for: view)
        }
    } else {
        UIView.transition(with: view.gameTileImageView,options: .transitionFlipFromBottom) {
            self.setimageAndColor(for: view)
        }
    }
cell.hasBeenFlipped = true
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...