swift - How to implicate UICollectionViewCell Flip animation -


i'm trying implicate uicollectionviewcell contains 2 different view flip on each over. have trouble, when flip first collectionviewcell tenth collectionviewcell flip over. please me

flipcollectionviewcontroller

class flipcollectionviewcontroller: uicollectionviewcontroller {  private struct storyboard {     static let flipcellreuseidentifier = "filpcell" }  override func viewdidload() {     super.viewdidload() }  override func didreceivememorywarning() {     super.didreceivememorywarning()  }  // mark: uicollectionviewdatasource override func numberofsectionsincollectionview(collectionview: uicollectionview) -> int {     //#warning incomplete method implementation -- return number of sections     return 1 }   override func collectionview(collectionview: uicollectionview, numberofitemsinsection section: int) -> int {     //#warning incomplete method implementation -- return number of items in section     return 20 }  var selectedcelldefaultframe:cgrect! var selectedcelldefaulttransform:cgaffinetransform!   override func collectionview(collectionview: uicollectionview, didselectitematindexpath indexpath: nsindexpath) {     nslog("select")     let cell = collectionview.dequeuereusablecellwithreuseidentifier(storyboard.flipcellreuseidentifier, forindexpath: indexpath) as! filpcollectionviewcell   }  override func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell {     let cell = collectionview.dequeuereusablecellwithreuseidentifier(storyboard.flipcellreuseidentifier, forindexpath: indexpath) as! filpcollectionviewcell     return cell }  } 

flipcollectionviewcell

class filpcollectionviewcell: uicollectionviewcell {  var back: uiview! var front: uiimageview! var showingback = true var initnumber:int = 0   required init(coder adecoder: nscoder) {     super.init(coder: adecoder)      let singletap = uitapgesturerecognizer(target: self, action: "tapped")     singletap.numberoftouchesrequired = 1      self.contentview.addgesturerecognizer(singletap)     self.contentview.userinteractionenabled = true  }  func tapped() {     front = uiimageview(image: uiimage(named: "queencard"))     = uiview(frame: self.frame)     back.backgroundcolor = uicolor.blackcolor()     self.contentview.addsubview(back)      if showingback {         nslog("showback")         uiview.transitionfromview(back, toview: front, duration: 1, options: uiviewanimationoptions.transitionflipfromleft, completion: nil)         showingback = false     } else {         uiview.transitionfromview(front, toview: back, duration: 1, options: uiviewanimationoptions.transitionflipfromright, completion: nil)         showingback = true     } }  } 

the cells being reused. when scrolling up, , cell goes out of view, cell reused @ bottom of view. in case flipped cell being reused. un-flip cell before reused.

before cell reused, ios calls method prepareforreuse(), un-flip cell, or reset custom property.

in case (untested code) :

override func prepareforreuse() {      if showingback {         uiview.transitionfromview(back, toview: front, duration: 0, options: uiviewanimationoptions.transitionnone, completion: nil)         showingback = false     } } 

this way, when cell reused un-flipped. if flipped cells stay flipped, should keep flipped-state in model.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -