ios - Unable to update the model layer upon CoreAnimation completion -
i have following function. it's purpose animate ui elements out of the screen's bounds.
func animateelementsout(elements: anyobject...) { var moveoutanimation : cakeyframeanimation = cakeyframeanimation(keypath: "transform"); moveoutanimation.delegate = self; var key1 : nsvalue = nsvalue(catransform3d: catransform3didentity); var key2 : nsvalue = nsvalue(catransform3d: catransform3dmaketranslation(-300, 0, 0)); var values : nsarray = [key1, key2]; var delayamount = 0.0; moveoutanimation.values = values; moveoutanimation.calculationmode = kcaanimationlinear; moveoutanimation.timingfunction = camediatimingfunction(name: kcamediatimingfunctioneasein); moveoutanimation.duration = 0.5; moveoutanimation.additive = true; element : anyobject in elements { delayamount += 0.1; moveoutanimation.removedoncompletion = true; moveoutanimation.begintime = cacurrentmediatime() + delayamount; element.layer?.addanimation(moveoutanimation, forkey: "move object along x axis"); // here lies problem element.layer?.position = cgpointmake(-330.0, 0.0); } }
now here's xcode complaining about, when try update property directly on model layer, elements not reset initial positions.
it's giving me these weird recommendations:
why can't set position of layer?
thanks in advance!
element.layer?.position
optional chain , may result in nil. can't assign nil. first make sure can layer , set position.
if let layer = element.layer { layer.position = cgpointmake(-330.0, 0.0); }
Comments
Post a Comment