我想在推送/关闭我的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的屏幕截图:

ios - Swift-使用UIImage动画显示/关闭ViewController-LMLPHP ios - Swift-使用UIImage动画显示/关闭ViewController-LMLPHP

就像我说的那样,我想拥有与视频完全相同的动画(也可以“拖动” ViewController,但这可能是另一个问题?)。

如果您不清楚,请随时询问。

我尝试搜索,但是找不到任何东西,所以我很感激:)

最佳答案

有一个很好的库可以执行此功能,称为Hero

如果要自己实现,则需要使用自己的UIViewControllerTransitioningDelegate

07-28 02:15
查看更多