iOS Swift Rotation Animation Not Staying Put -
i playing around rotating uiimageview. rotation animation works fine @ end of if image goes original orientation. below extension use rotate it:
extension uiview { func rotate(duration: cftimeinterval = 1.0, degrees:double, completiondelegate: anyobject? = nil) { let rotateanimation = cabasicanimation(keypath: "transform.rotation") rotateanimation.fromvalue = 0.0 let radians = cgfloat(degrees * m_pi / degrees) rotateanimation.tovalue = cgfloat(radians) rotateanimation.duration = duration if let delegate: anyobject = completiondelegate { rotateanimation.delegate = delegate } self.layer.addanimation(rotateanimation, forkey: nil) }
}
i have auto-layout turned off. missing?
in straight core animation have set property you're animating. animating alone shows effect , pops starting value. while setting fillmode
, removedoncompletion
work visually, actual value of rotation property on layer remains original value, not ending value specified in tovalue
property animation. end result only visual.
i suggest either use uiview
animation functions jan suggested or, can explicitly set property in animation--something like:
func rotate(duration: cftimeinterval = 1.0, degrees:double, completiondelegate: anyobject? = nil) { let rotateanimation = cabasicanimation(keypath: "transform.rotation") rotateanimation.fromvalue = 0.0 let radians = cgfloat(degrees * m_pi / degrees) rotateanimation.tovalue = cgfloat(radians) rotateanimation.duration = duration if let delegate: anyobject = completiondelegate { rotateanimation.delegate = delegate } self.layer.addanimation(rotateanimation, forkey: nil) // set layer's property self.layer.transform = catransform3dmakerotation(radians, 0.0, 0.0, 1.0) }
Comments
Post a Comment