【问题标题】:Swift - present/dismiss ViewController with UIImage animationSwift - 使用 UIImage 动画呈现/关闭 ViewController
【发布时间】: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)
}

这是我的CollectionViewViewController 我呈现/关闭的屏幕截图:

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

如果您有任何不清楚的地方,请随时询问。

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

【问题讨论】:

    标签: ios swift animation uicollectionview uiimageview


    【解决方案1】:

    有一个非常好的库可以实现这个功能,它叫做Hero

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

    【讨论】:

    • 你对Hero有经验吗?我现在正在挣扎。你能看看我最近的问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-15
    • 2013-04-28
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 2020-05-11
    相关资源
    最近更新 更多