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];
}
因此,如果我剛剛將我的'transform'屬性設置爲'CGAffineTransformMakeScale(1.0,1.0)',它會不會回到原始大小?我猜不出'CGAffineTransformMakeScale'和'CGAffineTransformScale'之間的區別。我的意思是我理解這些論點是什麼,但不是基礎功能。 – Steve 2010-10-21 15:56:44
您對CGAffine函數調用中指定的變換操作相對較多,因此TransformScale會將輸入相對於自身進行縮放。在這種情況下,您輸入當前的變換,該變換的縮放比例爲1:1。我不確定MakeScale的差異,也許它假設身份變換作爲輸入變換。 – Ben 2010-10-21 16:01:34