I am struggling with writing portion of an app which should behave like the native iphone photo app. Looked at iphone sdk app development book from Orielly which gave an exa
Many thanks to Adrian for his very simple and powerfull code sample. There was just one issue with this code : when the user made a "double scroll" (I.E. when he did not wait for the animation to stop and rescroll the scrollview again and again).
In this case, the refresh for the position of the 3 subviews is effective only when the "scrollViewDidEndDecelerating" method is invoked, and the result is a delay before the apparition of the subviews on the screen.
This can be easily avoided by adding few lines of code :
in the interface, just add this :
int refPage, currentPage;
in the implementation, initialize refPage and currentPage in the "viewDidLoad" method like this :
refpage = 0;
curentPage = 0;
in the implementation, just add the "scrollViewDidScroll" method, like this :
- (void)scrollViewDidScroll:(UIScrollView *)sender{
int currentPosition = floor(_scrollView.contentOffset.x);
currentPage = MAX(0,floor(currentPosition / 340));
//340 is the width of the scrollview...
if(currentPage != refPage) {
refPage = currentPage;
[self replaceHiddenLabels];
}
}
et voilà !
Now, the subviews are correctly replaced in the correct positions, even if the user never stop the animation and if the "scrollViewDidEndDecelerating" method is never invoked !