http://childhoodgamedev.qiniudn.com/xincheng_testGif.gif
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(250, 250, 200, 100)];
label.text = @"Hello world!";
label.textColor = [UIColor blackColor];
label.textAlignment = NSTextAlignmentLeft;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:25];
[self.view addSubview:label];
CGAffineTransform transform = CGAffineTransformIdentity;
label.transform = CGAffineTransformScale(transform, 2, 2);
[UIView animateWithDuration:4.0 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
label.transform = CGAffineTransformTranslate(label.transform, -100, 0);
} completion:^(BOOL finished) {
if (finished) {
NSLog(@"label %f %f %f %f", label.frame.origin.x, label.frame.origin.y, label.frame.size.width, label.frame.size.height);
[UIView animateWithDuration:3.0 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
NSLog(@"label %f %f %f %f", label.frame.origin.x, label.frame.origin.y, label.frame.size.width, label.frame.size.height);
label.transform = CGAffineTransformTranslate(label.transform, 100, 0);
} completion:NULL];
}
}];
有一个UILabel
名为 的实例label
,它按 2 比例缩放CGAffineTransformScale
。然后它从右向左移动,当动画完成时,它从左向右移动。
但奇怪的一点是:看起来位置不一样,分别是动画的终点(从右到左),动画的起点(从左到右)。但是 NSLog 告诉我,它们处于相同的位置。
http://childhoodgamedev.qiniudn.com/xincheng_QQ20150306-1.png
当我评论 statelabel.transform = CGAffineTransformScale(transform, 2, 2);
时,一切都很好。当标签改变方向移动时,右->左动画的结束位置就是左->右动画的开始位置。
所以我认为问题是由CGAffineTransformScale
. 有任何想法吗?