ios - Swift - 使用 UIImage 动画呈现/关闭 ViewController

标签 ios swift animation uicollectionview uiimageview

我希望在推送/关闭我的 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)
}

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

enter image description here enter image description here

就像我说的,我想要与视频中完全相同的动画(也能够“拖动-关闭”ViewController,但这可能是另一个问题?)。

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

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

最佳答案

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

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

关于ios - Swift - 使用 UIImage 动画呈现/关闭 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59663835/

相关文章:

ios - 如何为 iOS 13 的 SF Symbols 设置权重?

ios - UITextKit 中英文字符的顶部与行的顶部不对齐

jquery - 显示:none stopping initial translate3d animation

animation - 关键帧中的 CSS3 重叠 div 标签

objective-c - 无法关闭搜索 View

ios - 在离线模式下获取 iOS 中的时差

iOS:KVO + 动画 = 没有动画?

iOS在动画过程中显示标签或图像位置

ios - Swift - 在刷新控件中禁用默认重新加载表格 View

ios - 在 iOS 中,是否可以在特定时间启动基于区域的地理围栏?