如何使用FlipAnimation和Swift 3从每个CollectionViewCell打开新的ViewController
已实现collectionview它工作正常,但我希望FlipAnimation在从单元打开新的视图控制器并返回单元的同时关闭。如何达到同样的效果。因为我对动画没有任何想法。请帮忙,谢谢。 代码如何使用FlipAnimation和Swift 3从每个CollectionViewCell打开新的ViewController,animation,swift3,uicollectionview,uicollectionviewcell,Animation,Swift3,Uicollectionview,Uicollectionviewcell,已实现collectionview它工作正常,但我希望FlipAnimation在从单元打开新的视图控制器并返回单元的同时关闭。如何达到同样的效果。因为我对动画没有任何想法。请帮忙,谢谢。 代码 import UIKit class DashBoardVC: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
import UIKit
class DashBoardVC: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
{
@IBOutlet weak var logoutbtn: UIButton!
@IBOutlet weak var menubtn: UIButton!
var names = ["Dashboard","Add Book","Delete Book","Search Book","On Demand","About Us"]
var useimages = [UIImage(named:"dashboard_icon2"),UIImage(named:"book_blue_add"),UIImage(named:"book_blue_delete"),UIImage(named:"book_blue_view"),UIImage(named:"book_blue_new"),UIImage(named:"businesspeople2"),]
override func viewDidLoad()
{
super.viewDidLoad()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return names.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellcollect", for: indexPath) as! mycollectioncell
cell.collectLabel.text! = names[indexPath.row]
cell.collectimage.image = useimages[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
{
let padding : CGFloat = 15
let collectionViewSize = collectionView.frame.size.width - padding
return CGSize(width: collectionViewSize/2, height: collectionViewSize/2)
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
switch(indexPath.row)
{
case 0:
let desVC = storyboard.instantiateViewController(withIdentifier: "DashboardClick") as! DashboardClick
self.navigationController?.pushViewController(desVC, animated: true)
break
case 1:
let desVC = storyboard.instantiateViewController(withIdentifier: "AddBookVC") as! AddBookVC
self.navigationController?.pushViewController(desVC, animated: true)
break
case 2:
let desVC = storyboard.instantiateViewController(withIdentifier: "DeleteBookVC") as! DeleteBookVC
self.navigationController?.pushViewController(desVC, animated: true)
break
case 3:
let desVC = storyboard.instantiateViewController(withIdentifier: "SearchBookVC") as! SearchBookVC
self.navigationController?.pushViewController(desVC, animated: true)
break
case 4:
let desVC = storyboard.instantiateViewController(withIdentifier: "onDemandBookVC") as! onDemandBookVC
self.navigationController?.pushViewController(desVC, animated: true)
break
default:
break
}
}
override func viewWillAppear(_ animated: Bool)
{
self.navigationController?.navigationBar.isHidden = true
self.navigationController?.toolbar.isHidden = true
}
@IBAction func menutapped(_ sender: Any)
{
var appdelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
appdelegate.centerContainer?.toggle(MMDrawerSide.left, animated: true, completion: nil)
}
}
mycollectioncell.swift
import UIKit
class mycollectioncell: UICollectionViewCell {
@IBOutlet weak var collectLabel: UILabel!
@IBOutlet weak var collectimage: UIImageView!
}
这里的学生是NSObjectClass
var Arraydata:[Student] = []
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let arr = Arraydata[indexPath.row]
if indexPath.row == arr
{
let story = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController
UIView.beginAnimations("", context: nil)
UIView.setAnimationDuration(1.0)
UIView.setAnimationCurve(UIViewAnimationCurve.easeInOut)
UIView.setAnimationTransition(UIViewAnimationTransition.flipFromRight, for: (self.navigationController?.view)!, cache: false)
self.navigationController?.pushViewController(story, animated: true)
UIView.commitAnimations()
}
}
谢谢你的回复,但请参考我编辑的问题。我已经更新了代码。所以,试着在你的应用程序中添加代码,它100%工作,非常棒,这正是我想要的嘿,当它翻转时,场景后面有黑色背景,我们不能设置图像或任何颜色来代替它吗?嗨,rob,你能帮我解决我的最新问题吗?。