Wednesday, April 18, 2012

Is there a way to change content offset via Core Animation on UIScrollView with reusing views?

EDIT: I got some progress, so I have simplified and narrowed the problem: I have created new question, which is more clearer and more understandable I hope






I have very large horizontally scrolling UIScrollView, which is reusing its subviews. When user scrolls left, the rightmost view is moved to the leftmost position and its content is updated. Similarly when user scrolls right, the leftmost view is moved to the rightmost position and its content is updated. Similarly like in UITableView. This works nicely using scrollviewDidScroll: delegate method.



Now I need to change offset programatically, but with custom animation behaviour (inertia and bounce back to the final position).



To prototype this, I use



[UIView animateWithDuration:contentOffsetCADuration 
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
[self setContentOffsetNoDelegateCalls:contentOffset animated:NO];
}
completion:^(BOOL finish){
dispatch_async(dispatch_get_main_queue(), ^{
[timer invalidate];
});
}];


where I animate content offset with disabled delegate callback, so that views are not messed during animation. But I need something to simultaneously reuse and reposition them.



My solution is to create timer and call scrollViewDidScroll: manually so that reusing works as usual, parallel to animation. But it simply does not work - nothing is reused and scrollview's content after animation is in the same state as before animation -> formerly visible pages are moved out of screen.



So the question narrows down how to move subviews and update their content during animation?



Or maybe there might be completely different way doing this ...





No comments:

Post a Comment