为什么基本的UIScrollView没有几个按钮滚动? [英] why won't basic UIScrollView with a few buttons scroll?

查看:75
本文介绍了为什么基本的UIScrollView没有几个按钮滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么基本的UIScrollView没有几个按钮滚动?

Why won't basic UIScrollView with a few buttons scroll?

所以我所做的就是:


  • 创建基于视图的iPhone应用程序

  • 将UIScrollView拖入主控制器xib文件

  • 现在滚动视图坐在IB中的View的孩子

  • 在滚动视图中的IB增加它的视图高度高达1000

  • 向滚动视图添加一些按钮(所以它们显示为滚动视图的子项。)

  • 也创建了实例变量,并且在IB文件所有者scrollView中链接了属性IBOutlet,合成

  • 滚动视图的出口

  • 选中以确保IB中的滚动视图具有滚动启用属性勾选

  • Create a view based iPhone app
  • drag in a UIScrollView into the main controller xib file
  • the scrollview now sits as a child of View in IB
  • in IB in scrollview increase it's view height up to 1000
  • add some buttons to the scroll view (so they appear as children of the scroll view)
  • did create the instance variable also, and property IBOutlet, synthesize
  • linked in IB the File Owner scrollView outlet to the scroll view
  • checked to ensure the scroll view in IB had the attribute "scrolling enabled" ticked

但是在iPhone模拟器中它仍然不能让我滚动视图吗?

But still after all this in the iPhone simulator it won't let me scroll the view?

推荐答案

还有一件事要做:在滚动视图上设置 contentSize 属性一个合适的值:

Only one more thing you have to do: set the contentSize property on your scroll view to an appropriate value:

[scrollView setContentSize:CGSizeMake(
   scrollView.bounds.size.width,
   CGRectGetMaxY(bottommostSubview.frame)
)];

其中 bottommostSubview 是连接到滚动视图的子视图最接近底部。你也可以编写一个方法来自动查找这个视图,或者如果你知道大小永远不会改变就硬编码一个值。

Where bottommostSubview is an outlet connected to the subview of the scrollview that’s closest to the bottom. You could also write a method to find this view automatically, or just hard-code a value if you know the size will never change.

默认 contentSize CGSizeZero ,它可以有效地禁用滚动。

The default contentSize is CGSizeZero which effectively disables scrolling.

这篇关于为什么基本的UIScrollView没有几个按钮滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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