Ste*_*arp 6 iphone objective-c scrollview uiscrollview ios
我正在创建一个带有360度全景图像的iPhone应用程序.全景图是UIScrollView中的CATiledLayer.
我试图在图像上实现无限滚动(仅水平).我通过继承UIScrollView并实现setContentOffset:和setContentOffset:animated来完成此操作:当用户拖动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];
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在不影响减速的情况下更改contentOffset?
这里建议覆盖setContentOffset :(不是setContentOffset:animated :)修复了这个问题,但我似乎无法让它工作.
我也尝试过scrollRectToVisible:动画:没有成功.
任何关于如何解决这个问题的想法将不胜感激.谢谢!
编辑:
scrollViewDidScroll的代码:
-(void)scrollViewDidScroll:(PanoramaScrollView *)scrollView
{
[panoramaScrollView setContentOffset:panoramaScrollView.contentOffset];
}
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
-(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);
}
}
Run Code Online (Sandbox Code Playgroud)
我通过解决方法解决了该问题。我创建了一个具有 3 个全景宽度的全景图像(不会对性能产生太大影响,因为我使用的是CATiledLayer),并将decelerationRate属性设置为UIScrollViewDecelerationFast。因此,用户在减速停止之前无法滚动太远,并且如果减速在左全景图像或右全景图像中停止,则内容偏移量被改变回中间图像。这具有无限滚动的外观,这是我能想到的最佳解决方案。
| 归档时间: |
|
| 查看次数: |
3482 次 |
| 最近记录: |