我希望在推送/关闭我的 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
,用户只需点击一个按钮
:
@objc private func dismissView(){
self.dismiss(animated: true, completion: nil)
}
这是我的 CollectionView
和 ViewController
我呈现/关闭的屏幕截图:
就像我说的,我想要与视频中完全相同的动画(也能够“拖动-关闭”ViewController
,但这可能是另一个问题?)。
如果您有任何不清楚的地方,请随时提问。
我试着搜索它,但我真的找不到任何东西,所以我很感激你的帮助:)
最佳答案
有一个非常好的库可以实现这个功能,它叫做 Hero .
如果您想自己实现,则需要使用自己的 UIViewControllerTransitioningDelegate
关于ios - Swift - 使用 UIImage 动画呈现/关闭 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59663835/