学习UIScrollView的基础知识 [英] Learning the basics of UIScrollView

查看:70
本文介绍了学习UIScrollView的基础知识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直很难找到UIScrollView的好例子。即使是Apple的UIScrollView Suite我也觉得有点缺乏。

I've been having a very hard time finding good examples of UIScrollView. Even Apple's UIScrollView Suite I find a bit lacking.

我正在寻找一个教程或示例集,向我展示如何创建类似于iPhone Safari标签滚动的内容,当你从一个浏览器窗口缩小并可以轻弹到其他浏览器时。

I'm looking for a tutorial or example set that shows me how to create something similar to the iPhone Safari tab scrolling, when you zoom out from one browser window and can flick to others.

但是我很难在滚动视图中显示任何旧视图。我有一个设置了图像的视图,但当我将它添加到滚动视图时,我只得到一个黑色矩形,无论我放在我添加的视图中。

But I'm having a hard time just getting any old view showing within a scroll view. I have a view set up with an image in it, but when I add it to the scroll view, I only get a black rectangle, no matter what I put in the view I add.

任何链接或代码片段都会很棒!

Any links or code snippets would be great!

推荐答案

这是滚动查看指南Apple

基本步骤如下:


  1. 创建 UIScrollView 以及要放入的内容视图(在您的情况下为 UIImageView )。

  2. 使内容视图成为滚动视图的子视图。

  3. 将scrollview的内容大小设置为内容视图的帧大小。 这是人们经常忽略的一个非常重要的步骤。

  4. 将滚动视图放在某个窗口的某个窗口。

  1. Create a UIScrollView and a content view you want to put inside (in your case a UIImageView).
  2. Make the content view a subview of the scroll view.
  3. Set the content size of the scrollview to the frame size of the content view. This is a very important step that people often omit.
  4. Put the scroll view in a window somewhere.

关于分页行为,请查看UIScrollView的 pagingEnabled 属性。如果您需要滚动少于一整页,则需要使用 clipsToBounds 进行操作,与这个StackOverflow问题

As for the paging behavior, check out UIScrollView’s pagingEnabled property. If you need to scroll by less than a whole page you’ll need to play tricks with clipsToBounds, sort of the reverse of what is happening in this StackOverflow question.

这篇关于学习UIScrollView的基础知识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆