我有一个 scrollview,其中有 5 个宽度为 88 的图像视图.
I have a scrollview with 5 image views of width 88.
我希望 scrollview 滚动到每个图像视图 (非分页)
I want the scrollview to scroll to each image view (Not Paging)
和
我想在 iPhone 中制作一个无限滚动视图,这意味着当它滚动到最后一个项目时,它会在它旁边显示第一个项目..
I want to make an infinite scrollview in iPhone which means the when it scroll to last item it will display a first item next to it..
我一直在尝试按偏移量,但是当按偏移量移动它时它会停止,而且 我使用了苹果街道滚动条,它不允许我将每个元素停止在中心(就像选择器视图)..>
I have been trying by offset but it stops when move it by offset and also I have used apple street scroller which does not allow me to stop each element in center(just like Picker view)..
首先,我推荐使用 UITableView,这样可以保持较低的内存使用率.我在一个项目中成功使用的方法如下:
First of all, I recommend to use a UITableView so you can maintain the memory usage low. An approach that I had used successfully in a project is the following:
复制单元格的内容,我的意思是如果你有 5 个这样的项目:
Duplicate the content of your cells, I mean if you have 5 items in this way:
|1 |2 |3 |4 |5 |
| 1 | 2 | 3 | 4 | 5 |
您应该在表格末尾添加相同的内容(在具有可重用引擎的表格视图中,这不是什么大问题),以便看起来像这样:
You should add the same (In a table view with reusable engine that's not a big deal) at the end of the table in order to look like this:
|1 |2 |3 |4 |5 |1 |2 |3 |4 |5 |
| 1 | 2 | 3 | 4 | 5 | 1 | 2 | 3 | 4 | 5 |
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView == _yourScrollView) {
CGFloat currentOffsetX = scrollView.contentOffset.x;
CGFloat currentOffSetY = scrollView.contentOffset.y;
CGFloat contentHeight = scrollView.contentSize.height;
if (currentOffSetY < (contentHeight / 6.0f)) {
scrollView.contentOffset = CGPointMake(currentOffsetX,(currentOffSetY + (contentHeight/2)));
}
if (currentOffSetY > ((contentHeight * 4)/ 6.0f)) {
scrollView.contentOffset = CGPointMake(currentOffsetX,(currentOffSetY - (contentHeight/2)));
}
}
}
如果您几乎到达滚动的最后,上面的代码将滚动位置移动到顶部;或者,如果您几乎在顶部,则将您移至底部...
The code above move the scroll position at top if you almost reach the final of the scrolling; Or if you are almost on the top, moves you to the bottom...
这篇关于如何在 iPhone 中制作无限滚动视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何通过点击动画 UIImageview 以显示全屏?How to animate a UIImageview to display fullscreen by tapping on it?(如何通过点击动画 UIImageview 以显示全屏?)
停止 segue 并显示警报To stop segue and show alert(停止 segue 并显示警报)
iOS 5 故事板,以编程方式确定路径iOS 5 storyboard, programmatically determine path(iOS 5 故事板,以编程方式确定路径)
图标已经包含光泽效果Icon already includes gloss effects(图标已经包含光泽效果)
UIEdgeInsetsMake 是如何工作的?How does UIEdgeInsetsMake work?(UIEdgeInsetsMake 是如何工作的?)
UIProgressView 和自定义跟踪和进度图像(iOS 5 属性UIProgressView and Custom Track and Progress Images (iOS 5 properties)(UIProgressView 和自定义跟踪和进度图像(iOS 5 属性))