问题描述
目标:当用户在集合视图上平移时,当前单元格中的图像翻转一次。如果用户再次平移该图像(即使在相同的连续触摸中),图像将再次翻转。
问题:用户在图像上平移一次后,图像将不再翻转,无论是相同的触摸还是新的触摸。我知道这是一个逻辑问题。只是不确定如何正确操作这里的控制流......非常感谢任何人对此进行破解!
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 (将#修改为@)