【发布时间】:2014-06-26 00:11:19
【问题描述】:
我有以下功能。它的目的是使 ui 元素超出屏幕边界。
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;
for element : AnyObject in elements {
delayAmount += 0.1;
moveOutAnimation.removedOnCompletion = true;
moveOutAnimation.beginTime = CACurrentMediaTime() + delayAmount;
element.layer?.addAnimation(moveOutAnimation, forKey: "move object along the x axis");
// HERE LIES THE PROBLEM
element.layer?.position = CGPointMake(-330.0, 0.0);
}
}
现在这就是 xCode 抱怨的问题,当我尝试直接在模型层上更新属性时,元素不会重置到它们的初始位置。
它还给了我这些奇怪的建议:
为什么我不能设置图层的位置?
提前致谢!
【问题讨论】:
标签: ios ios7 core-animation swift