J'ai un UITableView chargement de ses données à partir du Web, et pendant le chargement des données il y a quelques cellules, pour indiquer le processus. Chaque cellule a un UIImageView à l'intérieur duquel je veux tourner constamment.Spinning UITableViewCells
A l'intérieur du UITableViewController j'ai obtenu ceci:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
//there are three "default" cells
return self.datasource.count > 0 ? self.datasource.count : 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(self.datasource.count)
{
//return a cell with loaded data
}
else
{
LoadingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LoadingIndicationCell"];
return cell;
}
}
LoadingTableViewCell a un fichier * .xib avec une sortie de référence correspondant à la UIImageView, appelé "cercle"
- (void)awakeFromNib {
self.circle.alpha = .3f;
self.spinning = NO;
[self startSpin];
}
- (void) spinWithOptions: (UIViewAnimationOptions) options {
NSLog(@"SPINNIN'");
// this spin completes 360 degrees every 2 seconds
[UIView animateWithDuration: 0.5f
delay: 0.0f
options: options
animations: ^{
_circle.transform = CGAffineTransformRotate(_circle.transform, M_PI/2);
}
completion: ^(BOOL finished) {
if (finished) {
if (_spinning) {
[self spinWithOptions: UIViewAnimationOptionCurveLinear];
} else if (options != UIViewAnimationOptionCurveEaseOut) {
[self spinWithOptions: UIViewAnimationOptionCurveEaseOut];
}
}
}];
}
- (void) startSpin {
if (!self.spinning) {
self.spinning = YES;
[self spinWithOptions: UIViewAnimationOptionCurveEaseIn];
}
}
- (void) stopSpin {
self.spinning = NO;
}
Il semble tourner 2 fois et s'arrête. Dans la console il y a 6 sorties "SPINNIN", deux pour chaque cellule, je suppose.
Je suis très novice dans le développement iOS, je l'ai essayé pendant toute la soirée. Btw, qu'adviendra-t-il de ces objets cellulaires lorsqu'ils seront remplacés par des cellules avec des données chargées? Où puis-je appeler stopSpin alors?
il semble que votre code ne possédent pas le problème. vous pouvez ajouter plus de journal et de point d'arrêt au bloc d'achèvement pour déboguer. Notez aussi parfois que le bloc d'achèvement appellera avec fini = NON. par exemple, quand la cellule est remplacée, elle sera supprimée en premier, cela arrêtera l'animation, et la fin du rappel sera terminée. NO – SolaWing
@SolaWing merci pour l'indication sur le drapeau "fini". J'ai légèrement modifié la méthode spinWithOptions et cela fonctionne désormais. – Alexander