uiview 内的 uiscrollview 不起作用

发布于 2025-01-02 08:15:29 字数 594 浏览 4 评论 0原文

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 containing UIView.
  • The next part is a bit of a hack. You need to assign a new frame to the containing UIView as well. However, the new frame CANNOT be the pre-existing size of your UIView. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神妖 2025-01-09 08:15:29

如果触摸落在滚动视图的框架内,您是否尝试过在 touchesBegan 中返回 NO

编辑:
确保您设置了滚动视图的内容大小([[selfscrollView] setContentSize:CGSizeMake(320,480)]; - 这些值并不重要),并且确保您选中“水平弹跳”并且/或“垂直弹跳”(取决于您想要的)以及“弹跳”:

弹跳设置屏幕截图

Have you tried returning NO in touchesBegan 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":

Bounce Settings Screenshot

凶凌 2025-01-09 08:15:29

您是否尝试过像这样设置 UiScrollView 的 contentsize 属性

self.scrollView.contentSize=CGSizeMake(320,860);  

Have you tried to set contentsize property of UiScrollView like this

self.scrollView.contentSize=CGSizeMake(320,860);  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文