ios - Image Scalling with multiple UICollectionView -


i building tvos app. have uitableview has around 25-30 sections. each section has 1 row , in each row have 1 horizontal uicollectionview has 1 section many rows. in each row in uicollectionview have image view scale when uicollectionviewcell selected.

i know can adjustsimagewhenancestorfocused case little more complicated. have 2 imageviews in uicollectionviewcell using adjustsimagewhenancestorfocused on bigger imageview if use on smaller imageview bad. that's why have use scaling on smaller imageview.

the issue facing when somewhere uicollectionviewcell indexpath messing up, results when go new uicollectionviewcell smaller image scaled , becomes bigger , bigger , cells very big because of on scaling

here image storyboard setup

enter image description here

here code great.

 func collectionview(collectionview: uicollectionview, didupdatefocusincontext context: uicollectionviewfocusupdatecontext, withanimationcoordinator coordinator: uifocusanimationcoordinator) {         guard let nextindexpath = context.nextfocusedindexpath else{             return         }           guard let nextfocusedcell = collectionview.cellforitematindexpath(nextindexpath) as? mycollectionviewcell else{             return          }          if nextfocusedcell.teacherimageview != nil {             coordinator.addcoordinatedanimations({ () -> void in                 let focusedtransform = cgaffinetransformscale(nextfocusedcell.teacherimageview.transform, 1.4, 1.4)                 nextfocusedcell.teacherimageview.transform =  focusedtransform                 },                 completion: nil             )          }          guard let previousindexpath = context.previouslyfocusedindexpath else {             return          }          guard let prevfocusedcell = collectionview.cellforitematindexpath(previousindexpath) as? mycollectionviewcell else{             return          }          if prevfocusedcell.teacherimageview != nil {             coordinator.addcoordinatedanimations({ () -> void in                 let focusedtransform = cgaffinetransformscale(prevfocusedcell.teacherimageview.transform, 1/1.4, 1/1.4)                 prevfocusedcell.teacherimageview.transform =  focusedtransform                 },                 completion: nil             )          }       } 

i figured out solution problem. there multiple uicollecetionviews in setup in each section of uitableview. function

func collectionview(collectionview: uicollectionview, didupdatefocusincontext context: uicollectionviewfocusupdatecontext, withanimationcoordinator coordinator: uifocusanimationcoordinator) 

is called multiple times when move vertically means when move between different rows of in image, , in case both cell @ indexpaths context.nextfocusedindexpath , context.previouslyfocusedindexpath not valid, 1 of them valid , other nil can't return if 1 of them nil have check both of them.

similary when move horizontially in 1 row or more precisely in 1 uitableview section in case

func collectionview(collectionview: uicollectionview, didupdatefocusincontext context: uicollectionviewfocusupdatecontext, withanimationcoordinator coordinator: uifocusanimationcoordinator)

is called once , both context.nextfocusedindexpath , context.previouslyfocusedindexpath valid, have change cgaffinetransform on both of them.

here updated code can further improved.

 func collectionview(collectionview: uicollectionview, didupdatefocusincontext context: uicollectionviewfocusupdatecontext, withanimationcoordinator coordinator: uifocusanimationcoordinator) {           let nextindexpath = context.nextfocusedindexpath         if let nextip = nextindexpath {             let nextfocusedcell = collectionview.cellforitematindexpath(nextip) as? mycollectionviewcell              if let nextcell = nextfocusedcell {                  if nextcell.teacherimageview != nil {                     coordinator.addcoordinatedanimations({ () -> void in                         let focusedtransform = cgaffinetransformscale(nextcell.teacherimageview.transform, 1.4, 1.4)                         nextcell.teacherimageview.transform =  focusedtransform                         },                         completion: nil                     )                 }             }         }           let previousindexpath = context.previouslyfocusedindexpath         if let previp = previousindexpath {             let previousfocusedcell = collectionview.cellforitematindexpath(previp) as? mycollectionviewcell              if let previouscell = previousfocusedcell {                  if previouscell.teacherimageview != nil {                     coordinator.addcoordinatedanimations({ () -> void in                         let focusedtransform = cgaffinetransformscale(previouscell.teacherimageview.transform, 1/1.4, 1/1.4)                         previouscell.teacherimageview.transform =  focusedtransform                         },                         completion: nil                     )                 }             }         }     } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -