iPhone - 实现 UIScrollView 的正确方法是什么?
我有两个 UIViewController,每个都有自己的 nib 文件。每个控制器都有不同的用途。我们的想法是添加一个 UIScrollController 并向其中添加两个 UIViewController,以便用户可以轻松地在它们之间滚动。
Q1)这可能吗?或者我是否理解了 UIScollControllers 的全部目的不正确,如果是这样,最好的选择是什么。
我一直在互联网上闲逛,我能想到的最好的办法是:
ScoreViewController *scoreController = [[ScoreViewController alloc] initWithNibName:@"ScoreViewController" bundle:nil];
scoreController.view.frame = CGRectMake(0.0f, 0.0f, 960f, 640f);
[self.scrollview addSubview:scoreController.view];
[scoreController release];
SettingsViewController *settingsController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
settingsController.view.frame = CGRectMake(0.0f, 0.0f, 960f, 640f);
[self.scrollview addSubview:settingsController.view];
[settingsController release];
此代码输入到我的 RootViewController 类中。它似乎不起作用,因为我无法在我添加的两个 UIViewControllers(分数和设置)之间滚动。屏幕上显示的所有内容都是添加的第二个控制器 - SettingsViewController。
Q2) 为什么这个坏了?
谢谢。 :)
I have two UIViewControllers each with their own nib files. Each controller serves a different purpose. The idea was to add a UIScrollController and add both UIViewControllers to it so the user can easily scroll between them both.
Q1) Is this even possible? Or have I got the whole purpose of UIScollControllers incorrect, if so, what is the best alternative.
I have been poking around the internet and the best I can come up with is this:
ScoreViewController *scoreController = [[ScoreViewController alloc] initWithNibName:@"ScoreViewController" bundle:nil];
scoreController.view.frame = CGRectMake(0.0f, 0.0f, 960f, 640f);
[self.scrollview addSubview:scoreController.view];
[scoreController release];
SettingsViewController *settingsController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
settingsController.view.frame = CGRectMake(0.0f, 0.0f, 960f, 640f);
[self.scrollview addSubview:settingsController.view];
[settingsController release];
This code is entered inside my RootViewController class. It doesn't seem to work though as I can't scroll between the two UIViewControllers I have added (score and settings). All what is displayed on the screen is the second controller added - the SettingsViewController.
Q2) Why is this broken?
Thank you. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,您正确放置了第一个控制器,然后将第二个控制器放置在其上方。
那么,你必须设置scrollView的contentSize
然后启用scrollView的分页;
这应该有效:)
Actually you place the first controller correctly, then you put the second above it.
then, you have to set the contentSize of the scrollView
Then enable the paging of the scrollView;
And that should work :)