【发布时间】:2012-06-29 18:43:45
【问题描述】:
我想通过左右滑动导航到画廊中的上一个和下一个图像,但我不想要上一个下一个按钮。在搜索时我遇到了滑动手势,这是我必须使用的还是简单的滚动视图?谁能提供想法如何做到这一点。有什么想法吗?
【问题讨论】:
-
我刚刚在类似的问题 [这里][1] [1] 中发布了一个答案(带代码):stackoverflow.com/questions/6244776/…
标签: objective-c ios
我想通过左右滑动导航到画廊中的上一个和下一个图像,但我不想要上一个下一个按钮。在搜索时我遇到了滑动手势,这是我必须使用的还是简单的滚动视图?谁能提供想法如何做到这一点。有什么想法吗?
【问题讨论】:
标签: objective-c ios
一个UIScrollView 水平扩展其contentSize 就足够了。
例如,假设您有 4 个 UIImageView 对象,它们位于 imageViewArray 中
for (int i = 0; i < 4; i++)
{
UIImageView *imgView = [imageViewArray objectAtIndex:i];
//one thing to note is while adding the image views, don't forget to change each views frame.origin.x property accordingly (in this case, each one will increase by the width of the view
//e.g.
imgView.frame = CGRectMake (self.view.frame.size.width * i, 0, self.view.frame.size.width, self.view.frame.size.height);
[yourScrollView addSubview:imgView];
}
[yourScrollView setContentSize:CGSizeMake(self.view.frame.size.width * 4, self.view.frame.size.height)]; // 4 is the number that will expand the scrollview horizontally
【讨论】:
pagingEnabled 属性,它将使滚动停止在其中一张图像上,否则滚动将在您停止滑动的点停止。正如 Apple 所说,如果此属性的值为 YES,则当用户滚动时,滚动视图会在滚动视图边界的倍数处停止。默认值为 NO。
我认为您应该使用启用分页的滚动视图。我建议不要自己实施画廊。为此目的使用一些开源库。查看three20库。
【讨论】:
我建议使用 UIScrollView 并将 pagingEnabled 设置为 YES。有了这个,您可以使用 UIScrollView 作为所有图像/图像视图的包装器。
【讨论】: