I am creating an iPhone app with a large, 360 degree, panorama image. The panorama is a CATiledLayer in a UIScrollView.
I am attempting to implement infinite scrolling on the image (horizontal only). I have done this by subclassing UIScrollView and implementing setContentOffset: and setContentOffset:animated: and this works perfectly when the user is dragging the scrollview. However, when the user has lifted their finger and the scrollview is decelerating, changing the contentOffset causes the deceleration to stop instantly.
- (void)setContentOffset:(CGPoint)contentOffset
{
CGPoint tempContentOffset = contentOffset;
if ((int)tempContentOffset.x >= 5114)
{
tempContentOffset = CGPointMake(1, tempContentOffset.y);
}
else if ((int)tempContentOffset.x <= 0)
{
tempContentOffset = CGPointMake(5113, tempContentOffset.y);
}
[super setContentOffset:tempContentOffset];
}
Is there any way to change the contentOffset without affecting deceleration?
It was suggested here that overriding setContentOffset: (not setContentOffset:animated:) fixes this issue, but I can't seem to get it working.
I have also tried scrollRectToVisible:animated: with no success.
Any ideas on how to fix this problem would be greatly appreciated. Thanks!
EDIT:
Code for scrollViewDidScroll:
-(void)scrollViewDidScroll:(PanoramaScrollView *)scrollView
{
[panoramaScrollView setContentOffset:panoramaScrollView.contentOffset];
}
I also tried this:
-(void)scrollViewDidScroll:(PanoramaScrollView *)scrollView
{
CGPoint tempContentOffset = panoramaScrollView.contentOffset;
if ((int)tempContentOffset.x >= 5114)
{
panoramaScrollView.contentOffset = CGPointMake(1, panoramaScrollView.contentOffset.y);
}
else if ((int)tempContentOffset.x == 0)
{
panoramaScrollView.contentOffset = CGPointMake(5113, panoramaScrollView.contentOffset.y);
}
}