iphone - 无限滚动 - setContentOffset : stops deceleration of UIScrollView

标签 iphone ios objective-c uiscrollview scrollview

我正在创建一个带有大型 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/

相关文章:

ios - 如何在头文件中声明一个 C 数组?

iphone - iOS中如何获取设备型号?

ios - 如何调整 UITableView 宽度以适应其内容?

iphone - 即使在从代码中分配高度后,UIwebview 也会自动缩小

ios - Splitviewcontroller逻辑不对,内容重复

iphone - 带有弯曲端的iOS Draw Rectangle

iphone - 向 UILabel 添加背景图像

php - 我们可以在 phonegap 上为 ipad 应用程序使用 opencart 或 zen cart 吗

ios - iOS地理围栏中可以为区域设置的最大和最小半径是多少

ios - 在iOS5的屏幕上同时显示两个摄像机的输出