我動畫(移動)一個子類的UIImageView像這樣:動畫UIView - 如何跟蹤位置?
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
[UIView setAnimationBeginsFromCurrentState:YES];
if (position == 0) position = 1;
if (position > 6) position--;
self.transform = CGAffineTransformMakeTranslation(position*120, 0);
[UIView commitAnimations];
然後,我想讓它脈動以突出顯示它:
CAKeyframeAnimation *bounce = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
CATransform3D forward = CATransform3DMakeScale(1.3, 1.3, 1);
CATransform3D back = CATransform3DMakeScale(0.7, 0.7, 1);
CATransform3D forward2 = CATransform3DMakeScale(1.2, 1.2, 1);
CATransform3D back2 = CATransform3DMakeScale(0.9, 0.9, 1);
[bounce setValues:[NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:CATransform3DIdentity],
[NSValue valueWithCATransform3D:forward],
[NSValue valueWithCATransform3D:back],
[NSValue valueWithCATransform3D:forward2],
[NSValue valueWithCATransform3D:back2],
[NSValue valueWithCATransform3D:CATransform3DIdentity],
nil]];
[bounce setDuration:0.6];
[[super layer] addAnimation:bounce forKey:@"bounceanimation"];
這所有的作品。它被120像素移動,但是當打電話給脈衝碼時,它會在原來的位置上跳動,而不是我剛纔移動的位置。爲什麼是這樣的,我該如何改變它?
tobias
終於明白了!謝謝!把它改成[self setFrame:CGRectMake(30 + position * 120,self.frame.origin.y,self.frame.size.width,self.frame.size.height)]; – 2012-03-30 18:19:08
沒問題!樂於幫助! – David 2012-03-30 22:06:49