我正在创建一个带有大型 360 度全景图像的 iPhone 应用程序。全景图是 UIScrollView 中的 CATiledLayer。
我正在尝试在图像上实现无限滚动(仅限水平)。我通过子类化 UIScrollView 并实现 setContentOffset: 和 setContentOffset:animated: 来完成此操作,当用户拖动 ScrollView 时,这非常有效。但是,当用户抬起手指并且 ScrollView 正在减速时,更改 contentOffset 会导致减速立即停止。
- (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];
}
有没有办法在不影响减速的情况下改变contentOffset?
有人建议here重写 setContentOffset:(不是 setContentOffset:animated:) 解决了这个问题,但我似乎无法让它工作。
我也试过 scrollRectToVisible:animated: 但没有成功。
任何有关如何解决此问题的想法将不胜感激。谢谢!
编辑:
scrollViewDidScroll 代码:
-(void)scrollViewDidScroll:(PanoramaScrollView *)scrollView
{
[panoramaScrollView setContentOffset:panoramaScrollView.contentOffset];
}
我也试过这个:
-(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);
}
}
最佳答案
代替
[scrollView setContentOffset:tempContentOffset];
使用
scrollView.contentOffset = tempContentOffset;
关于iphone - 无限滚动 - setContentOffset : stops deceleration of UIScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10397150/