-1
セルをタップして画像を拡大し、拡大した画像をタップすると各セルで閉じることができます。選択可能なチェックマークが付いています後で選択した画像をダウンロードしてください。コードはほとんどの場合、チェックマークを2回選択または選択解除する必要があることを除いてほとんど機能します。私は何が失われたのか本当に分かっていませんが、私のコードはここにあります:コレクションビューのチェックマークを2回タップしてタップしてください
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "photoCell", for: indexPath) as! PhotoCell
let tap = UITapGestureRecognizer(target: self, action: #selector(checkmarkWasTapped(_ :)))
cell.backgroundColor = .clear
cell.imageView.image = UIImage(contentsOfFile: imagesURLArray[indexPath.row].path)
cell.checkmarkView.checkMarkStyle = .GrayedOut
cell.checkmarkView.tag = indexPath.row
cell.checkmarkView.addGestureRecognizer(tap)
return cell
}
func checkmarkWasTapped(_ sender: UIGestureRecognizer) {
let checkmarkView = sender.view as! SSCheckMark
let indexPath = IndexPath(row: checkmarkView.tag, section: 0)
let imageURL = imagesURLArray[indexPath.row]
if checkmarkView.checked == true {
checkmarkView.checked = false
selectedImagesArray.remove(at: selectedImagesArray.index(of: imageURL)!)
} else {
checkmarkView.checked = true
selectedImagesArray.append(imageURL)
}
collectionView.reloadItems(at: [indexPath])
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
addZoomedImage(indexPath.row)
addGestureToImage()
addBackGroundView()
view.addSubview(selectedImage)
}
助けが素晴らしいでしょう。ありがとうございます
返信いただきありがとうございます。if文を追加して、各リロード時に選択内容を入れ替えることはありませんか? 'if!(boolArray [indexPath.row]){' – Wazza
boolArray [indexPath.row]がfalseになる前にユーザがブックマークしていないと、セルがロードされたときにcheckmarkViewがチェックされなくなります。それ以外の場合はチェックされます。あなたのcheckmarkViewがそのように働いていたら? –
viewdidloadでbool配列をfalseで埋めて、'if!(boolArray [indexPath.row]) 'を使用すると、それらはすべてチェックされませんが、チェックを選択するとすぐにチェックを外します。 [indexPath.row]) 'それらはすべてチェックされ、それらを選択すると何も起こりません。 – Wazza