Sto provando a vibrare/scuotere un elemento dell'interfaccia utente, vale a dire un controllo, come se fosse stato colpito, ed è in risonanza. Posso utilizzare Core Animation scuoterlo verticalmente, orizzontalmente o in entrambe, da un pixel:Il modo migliore per vibrare un elemento dell'interfaccia utente?
CABasicAnimation* rotationXAnimation;
rotationXAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"];
rotationXAnimation.fromValue = [NSNumber numberWithFloat: ((UIControl *) sender).center.y-1.0 ];
rotationXAnimation.toValue = [NSNumber numberWithFloat: ((UIControl *) sender).center.y+1.0 ];
rotationXAnimation.duration = 0.2;
rotationXAnimation.cumulative = NO;
rotationXAnimation.repeatCount = 10.0;
rotationXAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[((UIControl *) sender).layer addAnimation:rotationXAnimation forKey:@"upDownAnimation"];
O posso rotazione da un piccolo arco avanti e indietro attorno all'asse z (-M_PI * 0,02 e M_PI * 0.02) :
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.fromValue = [NSNumber numberWithFloat: -M_PI * 0.02 ];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 0.02 ];
rotationAnimation.duration = 0.2;
rotationAnimation.cumulative = NO;
rotationAnimation.repeatCount = 10.0;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[((UIControl *) sender).layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
Nessuno di questi sembra così piacevole. Qualcuno ha delle buone alternative? Vorrei soprattutto apprezzare le idee di keyPath da provare.
Grazie!
Aggiornamento:
Di seguito, dove sono contraenti ed espandere il controllo, è meglio, ma sto ancora cercando altre idee.
CABasicAnimation* scaleAnimation;
scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = [NSNumber numberWithFloat: 0.95 ];
scaleAnimation.toValue = [NSNumber numberWithFloat: +1.05 ];
scaleAnimation.duration = 0.1;
scaleAnimation.cumulative = NO;
scaleAnimation.repeatCount = 10.0;
scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[((UIControl *) sender).layer addAnimation:scaleAnimation forKey:@"scaleAnimation"];
questo è solo in una direzione - side-to-side - giusto? – mahboudz
Sì. Ma puoi creare un'animazione di fotogrammi chiave che utilizza un percorso nello stesso modo che anima il campo "posizione" che è un punto di partenza. –