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を変更する方法はありますか?
ここで、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);
}
}