J'essaye d'animer le décalage d'une table vers le bas, puis dans le bloc d'achèvement je le remettrais en place. Mais mon code ne fait rien dans le bloc d'achèvement:
-(void)viewDidAppear:(BOOL)animated { if (TRUE) { NSLog(@"animating table view"); [UIView animateWithDuration:.25 animations:^{ self.tableView.contentOffset = CGPointMake(self.tableView.contentOffset.x, self.tableView.contentOffset.y - 60); } completion:^(BOOL finished){ NSLog(@"completion block"); }]; } }
"bloc d'achèvement" ne sort jamais … des idées?
MODIFIER:
Ok, donc ça a quelque chose à voir avec mon UIREfreshControl:
- (void)viewDidLoad { [super viewDidLoad]; if (TRUE) { UIRefreshControl *refresh = [[UIRefreshControl alloc] init]; refresh.atsortingbutedTitle = [[NSAtsortingbutedSsortingng alloc] initWithSsortingng:@"Pull to Refresh"]; [refresh addTarget:self action:@selector(refreshTableView:) forControlEvents:UIControlEventValueChanged]; [self setRefreshControl:refresh]; } }
Lorsque le contrôle de rafraîchissement est ajouté, il ne triggers pas le blocage d'achèvement. Si je ne rajoute pas le contrôle, cela fonctionne comme prévu.
EDIT 2:
K, donc si je fais défiler la vue de la table, le bloc d'achèvement est alors déclenché:
2013-02-15 13:37:06.266 [1922:14003] animating table view 2013-02-15 13:37:14.782 [1922:14003] completion block
le code tel que écrit devrait se connecter "bloc d'achèvement" juste après "l'animation de la vue de la table", mais il a un timeout de 8 secondes parce que c'est quand j'ai fait défiler la vue de la table moi-même.
comment le "Pull to Refresh" ressemble à:
J'ai été en mesure de reproduire ce problème et j'ai trouvé une solution de contournement.
Lorsque vous utilisez un UIScrollView
, dont UITableView
hérite, vous ne pouvez pas modifier son contentOffset
n'est pas une propriété animable. Au lieu de cela, vous devez utiliser la méthode setContentOffset:animated:
Donc, ce que vous devez faire est comme suit:
UITableView
délégué UITableView
. Je l'ai fait sur viewDidAppear
. - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
, rebondir l'animation (vous pouvez append ici un timeout en utilisant performSelector:afterDelay:
Voici le code:
@interface MyViewController () @property (assign, nonatomic) BOOL shouldReturn; @end @implementation MyViewController -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if (TRUE) { NSLog(@"animating table view"); self.shouldReturn = YES; self.tableView.delegate = self; [self.tableView setContentOffset: CGPointMake(self.tableView.contentOffset.x, self.tableView.contentOffset.y - 60) animated:YES]; } } - (void)viewDidLoad { [super viewDidLoad]; if (TRUE) { UIRefreshControl *refresh = [[UIRefreshControl alloc] init]; refresh.atsortingbutedTitle = [[NSAtsortingbutedSsortingng alloc] initWithSsortingng:@"Pull to Refresh"]; [refresh addTarget:self action:@selector(refreshTableView:) forControlEvents:UIControlEventValueChanged]; [self setRefreshControl:refresh]; } } - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView { if (self.shouldReturn) { self.shouldReturn = NO; [self.tableView setContentOffset:CGPointZero animated:YES]; } } @end
Je l'ai utilisé et fonctionne bien. Sa solution alternative.
[UIView animateWithDuration:0.5 delay:0.1 options: UIViewAnimationOptionCurveEaseOut animations:^ { CGRect frame = self.adBannerView.frame; self.adBannerView.frame = frame; } completion:^(BOOL finished) { }];
essayez d'append un timeout et des options.