【问题标题】:Previous next navigation上一个 下一个 导航
【发布时间】:2012-06-29 18:43:45
【问题描述】:

我想通过左右滑动导航到画廊中的上一个和下一个图像,但我不想要上一个下一个按钮。在搜索时我遇到了滑动手势,这是我必须使用的还是简单的滚动视图?谁能提供想法如何做到这一点。有什么想法吗?

【问题讨论】:

标签: objective-c ios


【解决方案1】:

一个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。
【解决方案2】:

我认为您应该使用启用分页的滚动视图。我建议不要自己实施画廊。为此目的使用一些开源库。查看three20库。

http://three20.info/

【讨论】:

    【解决方案3】:

    我建议使用 UIScrollView 并将 pagingEnabled 设置为 YES。有了这个,您可以使用 UIScrollView 作为所有图像/图像视图的包装器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多