UIScrollView 无法使用 [scrollView setScrollEnabled: YES]

发布于 2024-10-10 07:29:27 字数 370 浏览 0 评论 0原文

在我的 .h 文件中,我有一个如下声明的 IBOutlet:

IBOutlet UIScrollView *scrollView;

我将 UIScrollView 连接到文件的所有者。

在我的 .m 文件中,viewDidLoad 中有以下内容:

[scrollView setContentSize:CGSizeMake(320, 600)];
[scrollView setScrollEnabled:YES];

但是当我尝试滚动时,没有任何反应。

您不需要设置 UIScrollViewDelegate,因为我有一些应用程序可以在不使用它的情况下滚动。

In my .h file, I have an IBOutlet declared like this:

IBOutlet UIScrollView *scrollView;

I wired my UIScrollView to File's Owner.

In my .m file I have the following in viewDidLoad:

[scrollView setContentSize:CGSizeMake(320, 600)];
[scrollView setScrollEnabled:YES];

But when I try to scroll, nothing happens.

You don't need to set the UIScrollViewDelegate because I've had apps that scroll without using it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

请止步禁区 2024-10-17 07:29:27

如果您使用的是 iOS 6,则在 .xib 文件中使用 Autolayout 可能会导致 UIScrollView 的行为方式与您不同期望它(即使您设置了一个大的 contentSize)。

您可以通过在项目导航器中选择相应的 .xib 文件并在文件检查器(右列)中取消选中“自动布局”来禁用自动布局。

您还可以调整自动布局设置(对此有各种线程)。

If you a are using iOS 6, using Autolayout in your .xib files can be the reason that your UIScrollView doesn't behave the way you expect it to (even though your setting a large contentSize).

You can disable Autolayout by selecting the respective .xib file in the Project Navigator and unchecking "Autolayout" in the File inspector (in the right column).

You can also adjust your Autolayout settings (there's various threads on this).

莳間冲淡了誓言ζ 2024-10-17 07:29:27

如果您在 xib 文件中采用了滚动视图,则无需使用以下行:

[scrollView setScrollEnabled:YES];

此外,您还应该检查与文件所有者的连接。

If you have taken scroll view in xib file then you do not need to below line:

[scrollView setScrollEnabled:YES];

Also you should check your connection with file's owner.

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