我只想用这个函数为我的 UIButton 的位置设置动画:
CABasicAnimation *moveUp;
moveUp = [CABasicAnimation animationWithKeyPath:@"position.y"];
moveUp.fromValue = [NSNumber numberWithFloat:self.retestBTN.frame.origin.y];
moveUp.toValue = [NSNumber numberWithFloat:self.retestBTN.frame.origin.y - 50];
moveUp.duration = 1.0;
moveUp.removedOnCompletion = NO;
moveUp.fillMode = kCAFillModeBoth;
moveUp.delegate = self;
[[retestBTN layer] addAnimation:moveUp forKey:@"y"];
然后我想稍后用那个函数把它动画化:
CABasicAnimation *moveDown;
moveDown = [CABasicAnimation animationWithKeyPath:@"position.y"];
moveDown.fromValue = [NSNumber numberWithFloat:self.retestBTN.frame.origin.y];
moveDown.toValue = [NSNumber numberWithFloat:self.retestBTN.frame.origin.y + 50];
moveDown.duration = 1.0;
moveDown.removedOnCompletion = NO;
moveDown.fillMode = kCAFillModeForwards;
[[retestBTN layer] addAnimation:moveDown forKey:@"y"];
但这不能正常工作,我的 UIButton 进入奇怪的位置......