gpt4 book ai didi

ios - 如何在 swift4 中为画廊从下到上制作 View 动画

转载 作者:行者123 更新时间:2023-11-29 05:53:18 25 4
gpt4 key购买 nike

我第一次尝试制作动画。这里我的任务是收集应该从底部开始动画的图像。我正在尝试遵循此link 。在这个例子中,哇,图像从下到上有动画,这就是我想要的。我尝试过什么,如下所示。我收到类似

的错误

Cannot invoke 'visibleCells' with no arguments

如果有人帮助我做到这一点,那就太好了。预先感谢您

import UIKit

class GalleryViewController: UIViewController {

@IBOutlet weak var collectionview_gallery: UICollectionView!
var imgarr = [UIImage(named: "1.png"),UIImage(named: "11.png"),UIImage(named: "111.png"),UIImage(named: "1111.png"),UIImage(named: "1.png"),UIImage(named: "11.png"),UIImage(named: "111.png"),UIImage(named: "1111.png"),UIImage(named: "1.png"),UIImage(named: "11.png"),UIImage(named: "111.png"),UIImage(named: "1111.png"),UIImage(named: "1.png"),UIImage(named: "11.png"),UIImage(named: "111.png"),UIImage(named: "1111.png"),UIImage(named: "1.png"),UIImage(named: "11.png"),UIImage(named: "111.png"),UIImage(named: "1111.png"),UIImage(named: "1.png"),UIImage(named: "11.png"),UIImage(named: "111.png"),UIImage(named: "1111.png"),UIImage(named: "1.png"),UIImage(named: "11.png"),UIImage(named: "111.png"),UIImage(named: "1111.png"),UIImage(named: "1.png"),UIImage(named: "11.png"),UIImage(named: "111.png"),UIImage(named: "1111.png"),UIImage(named: "1.png"),UIImage(named: "11.png"),UIImage(named: "111.png"),UIImage(named: "1111.png"),UIImage(named: "1.png"),UIImage(named: "11.png"),UIImage(named: "111.png"),UIImage(named: "1111.png"),UIImage(named: "1.png"),UIImage(named: "11.png"),UIImage(named: "111.png"),UIImage(named: "1111.png"),UIImage(named: "1.png"),UIImage(named: "11.png"),UIImage(named: "111.png"),UIImage(named: "1111.png")]
override func viewDidLoad() {
super.viewDidLoad()
collectionview_gallery.delegate = self
collectionview_gallery.dataSource = self
collectionview_gallery.register(UINib(nibName: "GalleryCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "GalleryCollectionViewCell")
}
override func viewWillAppear(_ animated: Bool) {
animateTable()
}

func animateTable() {
collectionview_gallery.reloadData()

let cells = collectionview_gallery.visibleCells()
let tableHeight: CGFloat = collectionview_gallery.bounds.size.height

for i in cells {
let cell: UICollectionViewCell = i as UICollectionViewCell
cell.transform = CGAffineTransformMakeTranslation(0, tableHeight)
}

var index = 0

for a in cells {
let cell: UICollectionViewCell = a as UICollectionViewCell
UIView.animateWithDuration(1.5, delay: 0.05 * Double(index), usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: nil, animations: {
cell.transform = CGAffineTransformMakeTranslation(0, 0);
}, completion: nil)

index += 1
}
}


}
extension GalleryViewController: UICollectionViewDelegate,UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 50

}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionview_gallery.dequeueReusableCell(withReuseIdentifier: "GalleryCollectionViewCell", for: indexPath) as! GalleryCollectionViewCell
cell.image_gallery.image = imgarr[indexPath.row]
return cell
}


}

最佳答案

这里是如何从下到上对动画进行成像的简单过程。在这里,gif 图像动画从下到上。您将遵循该流程。

@IBOutlet weak var eblLogo: UIImageView!
@IBOutlet var nrbcGif: UIImageView?

var heightScrren : CGFloat = 0.0

override func viewDidLoad() {
super.viewDidLoad()

let logoHeight = eblLogo.frame.origin.y + eblLogo.frame.height + 10
heightScrren = logoHeight
nrbcGif?.loadGif(name: "spin")

}

override func viewDidAppear(_ animated: Bool) {
UIView.animate(withDuration: 2, delay: 1, options: [.curveEaseOut],
animations: {

self.nrbcGif?.center.y -= self.view.bounds.height - 500
self.view.layoutIfNeeded()

}, completion: nil)
}

}

关于ios - 如何在 swift4 中为画廊从下到上制作 View 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55448693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com