我有一个 UIScrollView,我可以轻扫它以显示新 View 。我有一个按钮,我想以编程方式滚动浏览 View 。因此,如果我单击它一次,它将滚动到下一个 View 。我该如何实现?
这是 ScrollView 代码
- (void)scrollViewDidEndDecelerating:(UIScrollView *)aScrollView
{
NSUInteger offset = aScrollView.contentOffset.x;
NSUInteger width = aScrollView.contentSize.width;
int anIndex = (offset == 0) ? 0 : (int)(width/(width - offset));
selectedDeal = [deals objectAtIndex:(anIndex > [deals count]- 1 ? [deals count]- 1 : anIndex)];
}
最佳答案
[myScrollView scrollRectToVisible:myView.frame animated:TRUE];
这将滚动以便 myView
变得可见,假设 myView
被添加到 ScrollView 并且它还不可见。您需要跟踪当前可见 View ,并且在按钮处理程序中您需要将下一个 View 的框架作为参数传递给上述方法。
关于iphone - 如何以编程方式滚动 UIScrollView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5733688/