2010-10-21 77 views
4

下面是上一个问题的后续步骤。我的代码下面通过缩放和旋转来为正方形设置动画。它通过进行旋转变换并向其添加缩放变换来完成此操作。这工作正常。完成后,它会调用throbReset。我曾经有throbReset只是将self's transform设置为CGAffineTransformMakeScale,这将会对其进行缩放,但也会将其取消。所以我尝试着从目前的transform开始,并加入了不成比例的标准,但现在它没有做任何事情(可见)。无法撤消缩放变换而不撤消旋转变换


CGColorRef color = [[colorArray objectAtIndex:colorIndex] CGColor]; 
[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDuration:0.5f]; 
[UIView setAnimationDidStopSelector:@selector(throbReset:context:)]; 
// [[self layer] setFillMode:kCAFillModeForwards]; // apparently not needed 
CGAffineTransform xForm = CGAffineTransformMakeScale(2.0, 2.0); 
xForm = CGAffineTransformRotate(xForm, M_PI/4); 
[self setTransform:xForm]; 
[[self layer] setBackgroundColor:color]; 
[UIView commitAnimations]; 
} 

- (void)throbReset:(NSString *)animationID context:(void*)context { 
NSLog(@"-%@:%s fired", [self class], _cmd); 
[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:2.0]; 
CGAffineTransform xForm = [self transform]; 
xForm = CGAffineTransformScale(xForm, 1.0, 1.0); 
[self setTransform:xForm]; 
[UIView commitAnimations]; 
} 

回答

2

你只是比例大小相同,因为你基本上是说拿现在的变换和缩放1:1 X和1:1 Y.你可能想要做0.5,0.5而不是第二种方法中的1.0,1.0。

CGAffineTransform xForm = [self transform]; 
xForm = CGAffineTransformScale(xForm,0.5, 0.5); 

请记住,当您添加旋转以相反顺序进行时,请旋转然后缩放。如果涉及翻译,这将更加重要,但在这种情况下可能会以任何方式起作用。

+0

因此,如果我刚刚将我的'transform'属性设置为'CGAffineTransformMakeScale(1.0,1.0)',它会不会回到原始大小?我猜不出'CGAffineTransformMakeScale'和'CGAffineTransformScale'之间的区别。我的意思是我理解这些论点是什么,但不是基础功能。 – Steve 2010-10-21 15:56:44

+0

您对CGAffine函数调用中指定的变换操作相对较多,因此TransformScale会将输入相对于自身进行缩放。在这种情况下,您输入当前的变换,该变换的缩放比例为1:1。我不确定MakeScale的差异,也许它假设身份变换作为输入变换。 – Ben 2010-10-21 16:01:34