Xcode 4.2.1 UIScrollViews 不在情节提要中滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8762341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 4.2.1 UIScrollViews not scrolling in storyboard
提问by user1133100
So basically I have this project, where I have 4 different tab bar pages. 2 of them uses navigation controller & tab bar, and 2 are just view controllers. Now there is this one viewcontroller, which I need to add a scroll view to. So basically, I click on the item in the tab bar, it takes me to a view controller, where I can scroll down and up. I have been following Youtube Video Link, but I do not get it to work. The problem is that I use the exact code, and I change the ViewController class to the .h and .m name (ScrollViewViewController), and I put in a scroll view that has 320 x 1000, and a button at the top, but it doesn't scroll! How can I solve this problem?
所以基本上我有这个项目,我有 4 个不同的标签栏页面。其中 2 个使用导航控制器和标签栏,2 个只是视图控制器。现在有一个视图控制器,我需要向其中添加滚动视图。所以基本上,我点击选项卡栏中的项目,它会将我带到一个视图控制器,在那里我可以向下和向上滚动。我一直在关注Youtube Video Link,但我没有让它工作。问题是我使用了确切的代码,我将 ViewController 类更改为 .h 和 .m 名称(ScrollViewViewController),然后我放入了一个 320 x 1000 的滚动视图,顶部有一个按钮,但它不滚动!我怎么解决这个问题?
Note: That if you don't know my problem, but could very detailed walk me through on how to add a scroll view to storyboards in xcode 4.2, then that would be amazing :)!
注意:如果你不知道我的问题,但可以非常详细地指导我如何在 xcode 4.2 中向故事板添加滚动视图,那将是惊人的:)!
scrollerViewController.m:
scrollerViewController.m:
- (void)viewDidLoad {
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 1000)];
[super viewDidLoad];
}
scrollerViewController.h
滚动视图控制器.h
@interface scrollerViewController : UIViewController {
IBOutlet UIScrollView *scroller;
}
@end
And here comes a picture of the storyboard.
这是故事板的图片。
回答by barley
I need some of the code in order to really know your problem, but let me throw in my guess. You may be setting the size 320x1000 to the frame size of the scrollview by any chance? The frame size of the scrollview has to stay 320x480, and the contentSize should be 320x1000. Sorry if it was a wrong guess, but shouldn't do any harm :)
我需要一些代码才能真正了解您的问题,但让我猜测一下。您可能将 320x1000 的大小设置为滚动视图的框架大小?scrollview的frame size必须保持320x480,contentSize应该是320x1000。对不起,如果这是一个错误的猜测,但不应该造成任何伤害:)
Something like this in your ViewController of the scrollView...
像这样的东西在你的滚动视图的 ViewController 中......
- (void) viewDidLoad {
[super viewDidLoad];
UIScrollView * scrollView = self.view;
scrollView.frame = (CGRect){scrollView.frame.origin, CGSizeMake(320, 480)};
scrollView.contentSize = CGSizeMake(320, 1000);
scrollView.backgroundColor = [UIColor whiteColor]; // I am setting the white background, so that the scroll indicator is visible
}
I am assuming you are setting ScrollView as the top view of the ViewController in your Storyboard as in the attached image.
我假设您将 ScrollView 设置为 Storyboard 中 ViewController 的顶视图,如附加图像所示。
回答by Patrick
I followed the exact same movie and it did not work for me either. But this movie did: http://www.youtube.com/watch?v=YBlwepYK7Zs
我跟随了完全相同的电影,它对我也不起作用。但是这部电影做到了:http: //www.youtube.com/watch?v=YBlwepYK7Zs
I followed that one and now i got it to work.
我跟着那个,现在我开始工作了。
A bit late but might be more people looking for a solution to this.
有点晚了,但可能会有更多人在寻找解决方案。