uiview 内的 uiscrollview 不起作用
UIScrollView
本身就可以很好地工作(在 IB 中)。但是,一旦将 UIScrollView
放入 IB 中的 UIVIew
中,它就不再起作用。我这样做没有子类化,那么有什么关系呢?
回答
- 您必须确保在包含的
UIView
上选中Autoresize Subviews
。 - 下一部分是一些 hack。您还需要为包含的
UIView
分配一个新的frame
。但是,新的框架
不能是UIView
预先存在的尺寸。它必须具有不同的尺寸才能起作用。
如果您想要 InterfaceBuilder
中的 UIView
包含的大小,那么您需要执行以下操作:
self.frame = CGRectMake(0,0,0,0);
self.frame = [put your desired rect size here];
a UIScrollView
works just fine by it's self (in IB). However, once you put the UIScrollView
inside of a UIVIew
in IB, it no longer works. I'm doing this with no subclassing so what's the deal?
Answer
- You have to make sure
Autoresize Subviews
is checked on the containingUIView
. - The next part is a bit of a hack. You need to assign a new
frame
to the containingUIView
as well. However, the newframe
CANNOT be the pre-existing size of yourUIView
. It must be a different size for this to work.
If you want the size contained on your UIView
in InterfaceBuilder
then you need to do something like this:
self.frame = CGRectMake(0,0,0,0);
self.frame = [put your desired rect size here];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果触摸落在滚动视图的框架内,您是否尝试过在
touchesBegan
中返回NO
?编辑:
确保您设置了滚动视图的内容大小(
[[selfscrollView] setContentSize:CGSizeMake(320,480)];
- 这些值并不重要),并且确保您选中“水平弹跳”并且/或“垂直弹跳”(取决于您想要的)以及“弹跳”:Have you tried returning
NO
intouchesBegan
if the touch falls inside your scroll view's frame?Edit:
Make sure you set the scroll view's content size (
[[self scrollView] setContentSize:CGSizeMake(320,480)];
- the values do not matter) and make sure you check "Bounce Horizontally" and/or "Bounce Vertically" (depending on which you want) as well as "Bounces":您是否尝试过像这样设置 UiScrollView 的 contentsize 属性
Have you tried to set contentsize property of UiScrollView like this