ios - How to zoom out UIImageView content(image) on scroll of UITableView? -


i trying achieve effect:

https://cdn.dribbble.com/users/124059/screenshots/3727352/400.gif

for i'm doing:

override func tableview(_ tableview: uitableview, willdisplay cell: uitableviewcell, forrowat indexpath: indexpath) {     let cell = tableview.dequeuereusablecell(withidentifier: "cardcell", for: indexpath) as! cardtableviewcell      uiview.animate(withduration: 0.5, delay: 0.3, usingspringwithdamping: 0.1, initialspringvelocity: 0.5, options: .curveeaseinout, animations: {         cell.coverimageview.transform = cgaffinetransform(scalex: 0.7, y: 0.7)     }, completion: nil) } 

but code resizes uiimageview frame, not image inside of uiimageview.

how can improve code?

the trick mess frame of imageview make redraw , content mode changing. can manipulating frame or constraints , have masked inside view. run example , let me know.

import uikit  class viewcontroller: uiviewcontroller {      var imageview = uiimageview()     var maskview = uiview()     var frame : cgrect = .zero      override func viewdidload() {         super.viewdidload()         // additional setup after loading view, typically nib.         view.layoutifneeded()         imageview = uiimageview(frame: cgrect(x: 20, y: 40, width: view.bounds.width-40, height: view.bounds.height/2))         imageview.image = uiimage(named: "img")         imageview.contentmode = .scaleaspectfill           maskview = uiview(frame: cgrect(x: 20, y: 40, width: view.bounds.width-40, height: view.bounds.height/2))         maskview.addsubview(imageview)         maskview.layer.maskstobounds = true         maskview.layer.cornerradius = 6         self.view.addsubview(maskview)          //manipulate imageview make content mode seem change         // , have redraw         frame = imageview.frame         var newframe = frame         newframe.size.height += newframe.height         imageview.frame = newframe         imageview.center = maskview.center           let button = uibutton(frame: cgrect(x: 20, y: maskview.frame.maxy + 60, width: view.bounds.width - 40, height: 40))         button.settitle("animate", for: .normal)         button.settitlecolor(.blue, for: .normal)         button.addtarget(self, action: #selector(viewcontroller.pressed), for: .touchupinside)         self.view.addsubview(button)           let anotherbutton = uibutton(frame: cgrect(x: 20, y: button.frame.maxy + 20, width: view.bounds.width - 40, height: 40))         anotherbutton.settitle("reset", for: .normal)         anotherbutton.settitlecolor(.blue, for: .normal)         anotherbutton.addtarget(self, action: #selector(viewcontroller.reset), for: .touchupinside)         self.view.addsubview(anotherbutton)     }      func pressed() {         //animate         // screw around imageview original frame         // height constraints if constraint based         uiview.animate(withduration: 1.0, delay: 0, usingspringwithdamping: 1, initialspringvelocity: 1.0, options: .curveeaseout, animations: {             self.imageview.frame = self.maskview.bounds         }, completion: nil)      }      func reset() {         //reset big frame         var newframe = frame         newframe.size.height += newframe.height          uiview.animate(withduration: 1.0, delay: 0, usingspringwithdamping: 1.0, initialspringvelocity: 1.0, options: .curveeaseout, animations: {             self.imageview.frame = newframe             self.imageview.center = self.maskview.center         }, completion: nil)      }  } 

result: zoom


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -