我第一次尝试制作动画。在这里,我的任务是应从底部开始设置图像动画。我正在尝试遵循此link。在此示例中,哇,图像从下到上都是动画,这就是我想要的。我曾经尝试过的东西,在下面给出。我收到类似
的错误不能不带参数调用'visibleCells'
如果有人帮助我这样做,那就太好了。预先谢谢你
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
}
}
答案 0 :(得分:0)
这里是一个简单的过程,如何从下至上对动画进行成像。在此,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)
}
}