1

When a user selects a cell, i want the cell to animate from a square to a circle. I am using this code, but it does not animate, why?

Note: Code is in swift.

cell.layer.cornerRadius = 7
    cell.clipsToBounds = true


    UIView.animateWithDuration(0.5, animations: {
        cell.layer.cornerRadius = self.cell.frame.height / 2
        cell.clipsToBounds = true
    })
nachshon fertel
  • 145
  • 1
  • 1
  • 11
  • first of all corner radius isn't animatable with `animateWithDuration` see: http://stackoverflow.com/a/10674150/1495682 . Second thing - don't animate cell itself - animate its contentView, or better some contentView's subview – Kubba Apr 29 '15 at 22:32
  • then how do i animate it – nachshon fertel Apr 29 '15 at 22:34

1 Answers1

0

try this on some view inside cell's contentView

let corner = self.aView.frame.size.width/2

let animation = CABasicAnimation(keyPath: "cornerRadius")
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.fromValue = 0
animation.toValue = corner
animation.duration = 1.0

self.aView.layer.cornerRadius = corner
self.aView.layer.addAnimation(animation, forKey: "cornerRadius")
Kubba
  • 3,390
  • 19
  • 34