【发布时间】:2010-10-24 07:21:18
【问题描述】:
我正在开发一个更新 UITableView 和 UIScrollView 的应用程序。我喜欢 UITableView 更新的工作方式。在添加、删除或更新项目时,我会酌情调用insertRowsAtIndexPaths:withRowAnimation:、reloadRowsAtIndexPaths:withRowAnimation: 和deleteRowsAtIndexPaths:withRowAnimation:。然而,更新 UIScrollView 变得更具挑战性。
那我该怎么做呢?我的 UIScrollView 包含图像,我希望能够插入、更新和删除单个图像 - 带有动画 - 高效且流畅,并且可能以随机顺序。这种事情是怎么做的?
例如,我的 UIScrollViewDelegate 实现中有这样的代码,用于添加新图像:
if (newImageindex == currentImageIndex) {
[scrollView setNeedsDisplay];
[scrollView setContentOffset:portalView.contentOffset animated:YES];
} else if (newImageIndex < currentImageIndex) {
currentImageIndex++;
CGPoint offset = portalView.contentOffset;
offset.x += portalView.frame.size.width;
portalView.contentOffset = offset;
}
我认为这很接近,但并不完全正确。我最终添加了图像,但 UIScrollView 似乎滚动到视图中第一张图像之前的位置。如果我开始手动滚动它,就会出现第一张图像。就像它在我的图像中滚动到位置 -1。
该示例可能无助于突出我的问题,但肯定是动态重新调整 UIScrollView 中出现的图像的常见需求。这方面的最新技术是什么?
【问题讨论】:
标签: objective-c cocoa-touch uiscrollview