iOS: Why the animation runs well with CABasicAnimation but looks weird with animateWithDuration? -
here's simple demo rotating image view animation.
class viewcontroller: uiviewcontroller { @iboutlet weak var imageview: uiimageview! @ibaction func left() { animatewithtransform(catransform3dmakerotation(cgfloat(m_pi_4), 0, 0, 1)) } @ibaction func right() { animatewithtransform(catransform3dmakerotation(cgfloat(-m_pi_4), 0, 0, 1)) } func animatewithtransform(transform: catransform3d) { uiview.animatewithduration(1) { self.imageview.layer.transform = transform } } }
the animation runs smoothly. update right() to:
@ibaction func right() { animatewithtransform(catransform3dmakerotation(cgfloat(-m_pi_4), 0, 1, 0)) }
tap left right, animation not smooth more. image view jumps angle before starting animation. why's that?
update animatewithtransform() use cabasicanimation instead:
func animatewithtransform(transform: catransform3d) { let animation = cabasicanimation(keypath: "transform") animation.duration = 1 animation.fromvalue = nsvalue(catransform3d: imageview.layer.transform) animation.tovalue = nsvalue(catransform3d: transform) animation.timingfunction = camediatimingfunction(name: kcamediatimingfunctioneasein) imageview.layer.addanimation(animation, forkey: nil) imageview.layer.transform = transform }
the animation fine again.
so question why can't use animatewithduration here. bug? thanks.
---- update ---------------------------------
btw, image view centered constraints. constraint issue, i'm not sure.
i had same problem, reason animating catransform
, done on layer not on view, why uiview.animatewithduration
not respond it
Comments
Post a Comment