ios - Swift: UICollectionView locked to one cell after resizing custom cells -


i'm making custom attending button using uicollectionview 2 custom cells this: initial button

you can either click or drag choose status. when click cell, cells expands screen width, cell clicked visible. can swipe i'm out if change mind. funcitonality works.

i want implement buttons allow swiping follows:

swiping process

when swipe of button above threshold, button snaps status. however, after snap, not able swipe other cell anymore... can see small portion of when swipe:

enter image description here

the snap functionality done resizing sizes of cells. tried use reloaddata() followed scrollto item swiped to. not possible change cell.

anyone know how this? thanks.

my code - interesting part in scrollviewdidscroll:

class testcontroller: uiviewcontroller, uigesturerecognizerdelegate, uicollectionviewdelegate, uicollectionviewdatasource, uicollectionviewdelegateflowlayout{  var attendingcollectionview: uicollectionview! var imincell: imincustomcollectioncell = imincustomcollectioncell() var imoutcell: imoutcustomcollectioncell = imoutcustomcollectioncell() var hasnotrespondedyet = true var attendingstatus = false var attendingbuttonwidths = uiscreen.main.bounds.width var attendingbuttonheight = 100  override func viewdidload() {     super.viewdidload()     setupcollectionview() }  func setupcollectionview(){     let flowlayout = uicollectionviewflowlayout()     flowlayout.scrolldirection = .horizontal     flowlayout.minimumlinespacing = 0     self.attendingcollectionview = uicollectionview(frame: cgrect(x: 0, y: uiscreen.main.bounds.height-self.attendingbuttonheight, width: uiscreen.main.bounds.width, height: self.attendingbuttonheight), collectionviewlayout: flowlayout)     self.attendingcollectionview.delegate = self     self.attendingcollectionview.datasource = self     self.attendingcollectionview.ispagingenabled = true     self.attendingcollectionview.register(imincustomcollectioncell.self, forcellwithreuseidentifier: "imincell")     self.attendingcollectionview.register(imoutcustomcollectioncell.self, forcellwithreuseidentifier: "imoutcell")     self.attendingcollectionview.isuserinteractionenabled = true     self.attendingcollectionview.showshorizontalscrollindicator = false     view.addsubview(self.attendingcollectionview)     //never responeded before     if self.hasnotrespondedyet {         self.attendingcollectionview.isscrollenabled = true         self.attendingbuttonwidths = self.attendingbuttonwidths/2         self.attendingcollectionview.alwaysbouncehorizontal = true     } }  func collectionview(_ collectionview: uicollectionview, numberofitemsinsection section: int) -> int {     return 2 }  func collectionview(_ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell {     if indexpath.row == 0 {         let custom = attendingcollectionview.dequeuereusablecell(withreuseidentifier: "imincell", for: indexpath) as! imincustomcollectioncell         imincell = custom         return custom     } else {         let custom = attendingcollectionview.dequeuereusablecell(withreuseidentifier: "imoutcell", for: indexpath) as! imoutcustomcollectioncell         imoutcell = custom         return custom     } }  func scrollviewdidscroll(_ scrollview: uiscrollview) {     let screenwidth = uiscreen.main.bounds.width     let delta = scrollview.contentoffset.x/screenwidth     if delta <= 0{         if delta < -0.15 {             uiview.animate(withduration: 0.3, delay: 0, options: .curveeaseinout, animations: {                 let cell1 = self.imincell                 let cell2 = self.imoutcell                 cell1.frame = cgrect(x: 0, y: 0, width: self.attendingbuttonwidths*2, height: self.attendingbuttonheight)                 cell1.iminlabel.frame = cgrect(x: screenwidth/2-cell1.iminlabel.frame.width/2, y: cell1.iminlabel.frame.miny, width: cell1.iminlabel.frame.width, height: cell1.iminlabel.frame.height)                 cell2.frame = cgrect(x: uiscreen.main.bounds.width, y:0,width: self.attendingbuttonwidths*2,height: self.attendingbuttonheight)                 cell2.imoutlabel.frame = cgrect(x: 10, y: cell2.imoutlabel.frame.miny, width: cell2.imoutlabel.frame.width, height: cell2.imoutlabel.frame.height)                 cell1.iminlabel.textcolor = uicolor.white                 }, completion: { (f) in                     self.attendingcollectionview.isscrollenabled = true                     self.attendingcollectionview.ispagingenabled = true                     self.hasnotrespondedyet = false             })         }     } }  func collectionview(_ collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, sizeforitemat indexpath: indexpath) -> cgsize{     if self.hasnotrespondedyet {         return cgsize(width: self.attendingbuttonwidths, height: attendingcollectionview.frame.size.height)     } else {         return cgsize(width: self.attendingbuttonwidths, height: attendingcollectionview.frame.size.height)     } } 

}

class imincustomcollectioncell: uicollectionviewcell {  var iminlabel: uilabel! override init(frame: cgrect){     super.init(frame: frame)     self.iminlabel = uilabel(frame: self.frame)     self.iminlabel.text = "i'm in"     self.iminlabel.sizetofit()     self.iminlabel.frame = cgrect(x: self.frame.width/2-self.iminlabel.frame.width/2, y: self.frame.height/2-self.iminlabel.frame.height/2, width: self.iminlabel.frame.width, height: self.iminlabel.frame.height)     addsubview(self.iminlabel) } required init?(coder adecoder: nscoder) {     fatalerror("init(coder:) has not been implemented") } 

}

class imoutcustomcollectioncell: uicollectionviewcell {}//similar logic above 


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -