2010-11-21 5 views
18

J'utilise UIScrollView et en utilisant scrollRectToVisible: animé Cela fonctionne très bien pour moi. Mais je veux faire défiler lentement jusqu'à un endroit pour que l'utilisateur puisse remarquer l'effet. Est-ce possible? J'essaye le code suivant, mais n'ai pas réussi.iphone - UIScrollview - scrollRectToVisible avec animation lente

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationDuration:2.0]; 
[scrlView scrollRectToVisible:<<some cgrect>> animated:YES];    
[UIView commitAnimations];   
+0

double possible (http://stackoverflow.com/questions/1558262/uiscrollview-scrollrecttovisible-at-custom-speed) [UIScrollView scrollRectToVisible à vitesse personnalisé] – tbodt

Répondre

55

La solution est en fait assez facile. Si vous utilisez [scrollView scrollRectToVisible:frame animated:YES] le scrollview lancera sa propre animation, donc pour animer avec votre durée, vous devez utiliser [scrollView scrollRectToVisible:frame animated:NO] dans votre animation.

En d'autres termes: Cela fonctionnera.

[UIView animateWithDuration:3 
         delay:0 
        options:UIViewAnimationOptionCurveEaseInOut 
       animations:^{ [scrollView scrollRectToVisible:frame animated:NO]; } 
       completion:NULL];