2

Have implemented collectionview it works fine but i want FlipAnimation while opening a new view controller from the cell and dismiss back to the cell. how to achieve the same.As i dont have any idea of Animation. Please Help.Thank you. code

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!



}
deltami
  • 303
  • 2
  • 17

1 Answers1

1

here Student is 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()

        }
    }
Amul4608
  • 1,390
  • 14
  • 30
  • thanks for the reply but plz refer my edited question. – deltami Jul 08 '17 at 07:10
  • i have Updated the code . so try to put code in your app it is 100% working – Amul4608 Jul 08 '17 at 09:29
  • thanks awesome this is exactly what i want hey when it turns to flip there is black background behind the scene can't we set the image or anycolor inplace of that?. – deltami Jul 08 '17 at 09:44
  • hi rob will you help me to solve my latest question ?https://stackoverflow.com/questions/45436010/segue-to-multiple-storyboards-from-the-same-sidemenu-in-swift3. – deltami Aug 01 '17 at 11:08