Come si ruota UIView
, UIImageView
o CALayer
animato a 360 gradi senza utilizzare OpenGL ES?Come ruotare UIView, UIImageView o CALayer animati 360˚?
5
A
risposta
3
Presumibilmente si intende animare la rotazione di un UIImage
intorno a 360 °? Nella mia esperienza, il modo per compiere una rotazione completa cerchio è a catena più animazioni insieme:
- (IBAction)rotate:(id)sender
{
[UIView beginAnimations:@"step1" context:NULL]; {
[UIView setAnimationDuration:1.0];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
[imageView.transform = CGAffineTransformMakeRotation(120 * M_PI/180);
} [UIView commitAnimations];
}
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
if ([animationID isEqualToString:@"step1"]) {
[UIView beginAnimations:@"step2" context:NULL]; {
[UIView setAnimationDuration:1.0];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
imageView.transform = CGAffineTransformMakeRotation(240 * M_PI/180);
} [UIView commitAnimations];
}
else if ([animationID isEqualToString:@"step2"]) {
[UIView beginAnimations:@"step3" context:NULL]; {
[UIView setAnimationDuration:1.0];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
imageView.transform = CGAffineTransformMakeRotation(0);
} [UIView commitAnimations];
}
}
ho lasciato la curva (invece che lineare) al posto easeIn/easeOut
, in modo da poter vedere le singole animazioni.
28
#import <QuartzCore/QuartzCore.h>
CABasicAnimation *fullRotation;
fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = @(0.0);
fullRotation.toValue = @((360.0 * M_PI)/180.0);
fullRotation.duration = 3.5f;
fullRotation.repeatCount = MAXFLOAT;
[view.layer addAnimation:fullRotation forKey:@"rotation-animation"];
Se si desidera cambiare il punto di ancoraggio a ruota attorno allora si può fare
CGRect frame = view.layer.frame;
self.anchorPoint = CGPointMake(0.5, 0.5); // rotates around center
self.frame = frame;
Problemi correlati
- 1. Angoli arrotondati UIView o UIImageView
- 2. Animazione di UIView mascherato, CALayer
- 3. IOS: ruotare un UIImageView
- 4. UIImageView compilare UIView
- 5. come ruotare CALayer in un punto
- 6. Come ruotare un UIImageView in Interface Builder?
- 7. Come posso aggiungere un'ombra a un cerchio UIImageView o UIView?
- 8. antialiasing bordi UIView dopo trasformazione utilizzando CALayer di trasformazione
- 9. UIView/CALayer: Trasforma trigger layoutSubviews in superview
- 10. È possibile copiare CALayer da UIView?
- 11. Come aggiungere un UIImageView a UIImageView in modo programmatico, quindi aggiungere UIImageView a un altro UIView?
- 12. CATransform3DRotate ruota per 360 gradi
- 13. Ombra non appare per UIView utilizzando CALayer
- 14. Applicando Box2D fisica per UIView vs. CALayer
- 15. UIImageView "schiacciato" dopo CGAffineTransformMakeRotation
- 16. UIImageView vs UIView w/Image - efficienza
- 17. UIImageView ritaglio immagine sulla base di UIView mascherare
- 18. Avvolgimento/deformazione di un CALayer/UIView (o OpenGL) in 3D (iPhone)
- 19. Proporzioni di autolayout per UIImageView/UIView
- 20. Come faccio ad aggiungere un bagliore esterno a un UIImage o UIImageView o UIView
- 21. Prestazioni del CALayer rispetto alle prestazioni di UIImageView
- 22. ruotare un UIView attorno al suo centro, ma più volte
- 23. Come eseguire l'antialias su un UIView ruotato (NOT UIImageView)
- 24. Come posso lanciare un CALayer con CATransform3D?
- 25. UIImageView mostra MOLTO più veloce di CG o CALayer. Qualcuno sa perché?
- 26. CALayer autoresizingMask non per iOS SDK?
- 27. Applicazione di più trasformazioni a un UIView/CALayer
- 28. come scurire un UIImageView
- 29. Come ruotare il testo Swing?
- 30. Bordo UIView con effetto dissolvenza o sfocatura
Ti rendi conto che la rotazione 360˚ vi darà la stessa identica immagine, giusto? – SteamTrout
Trovo triste che ho iniziato a provare a pensare a una soluzione prima che me ne rendessi conto. – jtbandes
@Steam Trout: solo se si desidera che sia istantaneo. – JeremyP