UIScrollView Always Animation!

I have a little problem with UIScrollView. Basically, I use the code from the PageControl sample application with some changes. I am adding a scroll view to my navigation stack, I want it to be on a specific page when it gets there. I'm trying to use the UIScrollView scrollToRect: animated method, but even if I pass NO, it still animates! Here's the code snippet:

- (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];
}

Does anyone know why?

Thank!

+3
source share
2 answers

I ended up using CoreAnimation to create custom animations that work very well:

- (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];
}
+1
source

Try using setContentOffset:animated::

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

Source: https://habr.com/ru/post/1763335/


All Articles