Nel mio progetto xcode ho un UIImage. Voglio farlo tremare (animazione) da sinistra a destra un po '. Ho scritto questo codice, tuttavia, non funziona.Come rendere l'animazione "shaking"
-(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];
}
Potrebbe dirmi per favore, come posso far tremare la mia immagine?
Grazie! Ma devo aggiungere qualche framework/libreria al progetto? Xcode dà un errore a causa della prima riga. – SmartTree
aggiungi la struttura 'QuartzCore' al tuo progetto! e aggiungi anche "#import" nel file che vuoi utilizzare per l'animazione, o meglio ancora nel file di intestazione del prefisso delle app in modo da poterlo vedere da qualsiasi classe. –
jere
Meraviglioso! E un'altra domanda: che cosa è [centro di sé]? – SmartTree