【发布时间】:2020-04-27 01:12:46
【问题描述】:
我希望在推送/关闭我的ViewController 时有一个动画。
向您展示我的意思的最佳方式是查看 N26:Animation
在我的例子中,我有一个CollectionView,用户可以在其中单击cell 以访问下一个ViewController,我使用tapCallback 处理它:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// if indexPath.item is less than data count, return a "Content" cell
if indexPath.item < dataSourceArray.count {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ContentCell", for: indexPath) as! ContentCell
// set cell label
cell.cellLabel.text = dataSourceArray[indexPath.item].name
// set cell image
cell.wishlistImage.image = dataSourceArray[indexPath.item].image
if cell.wishlistImage.image == images[2] || cell.wishlistImage.image == images[3] {
cell.priceLabel.textColor = .gray
cell.priceEuroLabel.textColor = .gray
cell.wishCounterLabel.textColor = .gray
cell.wünscheLabel.textColor = .gray
}
// set background color
cell.imageView.backgroundColor = dataSourceArray[indexPath.item].color
cell.wishCounterView.backgroundColor = dataSourceArray[indexPath.item].color
cell.priceView.backgroundColor = dataSourceArray[indexPath.item].color
cell.customWishlistTapCallback = {
// track selected index
self.currentWishListIDX = indexPath.item
let vc = self.storyboard?.instantiateViewController(withIdentifier: "WishlistVC") as! WishlistViewController
vc.wishList = self.dataSourceArray[self.currentWishListIDX]
vc.theTableView.tableView.reloadData()
self.present(vc, animated: true, completion: nil)
}
return cell
}
要关闭ViewController,用户只需点击button:
@objc private func dismissView(){
self.dismiss(animated: true, completion: nil)
}
这是我的CollectionView 和ViewController 我呈现/关闭的屏幕截图:
就像我说的那样,我希望拥有与视频中完全相同的动画(也可以“拖放”ViewController,但这可能是另一个问题?)。
如果您有任何不清楚的地方,请随时询问。
我尝试搜索,但我真的找不到任何东西,所以我很感激任何帮助:)
【问题讨论】:
标签: ios swift animation uicollectionview uiimageview