在我的xcode項目中,我有一個UIImage。我想讓它從左向右搖晃(動畫)一點點。我寫了這個代碼,但是,它不工作。如何製作「搖動」動畫
-(void)errorShake
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[lockImage setTransform:CGAffineTransformMakeRotation(-5 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(-10 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(-15 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(-20 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(-15 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(-10 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(-5 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(0 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(5 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(10 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(15 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(20 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(15 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(10 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(5 * M_PI/180.0)];
[lockImage setTransform:CGAffineTransformMakeRotation(0 * M_PI/180.0)];
[UIView commitAnimations];
}
請問你能告訴我,我該如何讓我的形象動搖?
謝謝!但是,我需要爲項目添加任何框架/庫嗎?由於第一行,Xcode提供了一個錯誤。 – SmartTree
將'QuartzCore'框架添加到您的項目!並在要使用該動畫的文件中添加'#import',或者在應用程序前綴頭文件中添加''import',以便您可以從任何類中看到它。 –
jere
太棒了!還有一個問題:什麼是[自我中心]? – SmartTree