CGAffineTransform动画未在正确位置结束



我正在对UILabel应用翻译,这应该会导致标签在其开始的x位置结束,但由于某种原因,它似乎向左挂起。

[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.1 initialSpringVelocity:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
    NSLog(@"PLAYLABEL BEGIN X %f", self.playLabel.frame.origin.x);
    self.playLabel.transform = CGAffineTransformMakeTranslation(-10, 0);
    self.playLabel.transform = CGAffineTransformMakeTranslation(+20, 0);
    self.playLabel.transform = CGAffineTransformMakeTranslation(-10, 0);
} completion:^(BOOL finished) {
    NSLog(@"PLAYLABEL DONE X %f", self.playLabel.frame.origin.x);
}];

动画之前标签的原点.x为119.500000,完成后原点.x为109.500000。我对翻译的应用方式有错吗?如果我从原点变换-10,然后从其当前位置变换+20,那么标签应该只从原点变换+10。因此-10,应该会导致标签.x位于原来的位置。

CGAffineTransformMake创建一个变换矩阵。看起来你在想你创建的3个矩阵是按顺序应用的。但是,您正在重写矩阵两次。调用animate duration时,它会应用self.playlabel.transform,这等于上次设置它的时间:CGAffineTransformMakeTranslation(-10, 0);

最新更新