2010-09-05 4 views
3

J'ai un petit problème avec UIScrollView. Fondamentalement, j'utilise le code de l'exemple d'application PageControl avec quelques modifications. J'ajoute la vue de défilement à ma pile de navigation, je veux qu'elle soit sur une page spécifique quand elle y arrivera. J'essaie d'utiliser la méthode UIScrollView scrollToRect: animated: mais même si je passe en NO, c'est toujours animé! Voici un extrait de code:UIScrollView Toujours animé!

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
NSUInteger row = indexPath.row; 
viewController.currentPage = row; 

CGRect frame = viewController.scrollView.frame; 
frame.origin.x = frame.size.width * row; 
frame.origin.y = 0; 
[viewController.scrollView scrollRectToVisible:frame animated:NO]; 

[self.navigationController pushViewController:viewController animated:YES]; 
[tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 

Est-ce que quelqu'un sait pourquoi?

Merci!

Répondre

1

Je fini par utiliser CoreAnimation pour faire une animation personnalisée, qui fonctionne très bien:

- (void) altAnimatePopViewControllerAnimated:(BOOL)animated 
{ 
[CATransaction begin]; 

CATransition *transition; 
transition = [CATransition animation]; 
transition.type = kCATransitionPush;   // Use any animation type and subtype you like 
transition.subtype = kCATransitionFromRight; 
transition.duration = 0.3; 

CATransition *fadeTrans = [CATransition animation]; 
fadeTrans.type = kCATransitionFade; 
fadeTrans.duration = 0.3; 


[CATransaction setValue:(id)kCFBooleanTrue 
       forKey:kCATransactionDisableActions]; 

[[[[self.view subviews] objectAtIndex:0] layer] addAnimation:transition forKey:nil]; 
[[[[self.view subviews] objectAtIndex:1] layer] addAnimation:fadeTrans forKey:nil]; 



[self popViewControllerAnimated:YES]; 
[CATransaction commit]; 
} 

- (void) altAnimatePushViewController:(UIViewController *)viewController Animated:(BOOL)animated 
{ 
[CATransaction begin]; 

CATransition *transition; 
transition = [CATransition animation]; 
transition.type = kCATransitionPush;   // Use any animation type and subtype you like 
transition.subtype = kCATransitionFromRight; 
transition.duration = 0.3; 

CATransition *fadeTrans = [CATransition animation]; 
fadeTrans.type = kCATransitionFade; 
fadeTrans.duration = 0.3; 


[CATransaction setValue:(id)kCFBooleanTrue 
       forKey:kCATransactionDisableActions]; 

[[[[self.view subviews] objectAtIndex:0] layer] addAnimation:transition forKey:nil]; 
[[[[self.view subviews] objectAtIndex:1] layer] addAnimation:fadeTrans forKey:nil]; 



[self pushViewController:viewController animated:YES]; 
[CATransaction commit]; 
} 
3

Essayez d'utiliser setContentOffset:animated::

int xOffset = viewController.scrollView.frame.size.width * row; 
[viewController.scrollView setContentOffset:CGPointMake(xOffset, 0) animated:NO]; 
+0

Bonne idée, ça n'a pas ... Je fini par utiliser une animation personnalisée. –

+0

Cela a bien fonctionné là où scrollToRect n'a pas ... Merci! –