UIScrollView 无法使用 [scrollView setScrollEnabled: YES]
在我的 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是 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 largecontentSize
).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).
如果您在 xib 文件中采用了滚动视图,则无需使用以下行:
此外,您还应该检查与文件所有者的连接。
If you have taken scroll view in xib file then you do not need to below line:
Also you should check your connection with file's owner.