【发布时间】:2012-05-10 22:44:33
【问题描述】:
我正在创建一个带有 360 度全景图像的 iPhone 应用。全景图是 UIScrollView 中的 CATiledLayer。
我正在尝试在图像上实现无限滚动(仅限水平)。我通过继承 UIScrollView 并实现 setContentOffset: 和 setContentOffset:animated: 来做到这一点,当用户拖动滚动视图时,这非常有效。但是,当用户抬起手指并且滚动视图正在减速时,更改 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: (not 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);
}
}
【问题讨论】:
标签: iphone ios objective-c uiscrollview scrollview