正如@Departamento B 所提到的,向主视图添加新的滚动视图并不是真正必要的,因此您应该删除这一行。
基本上,UIScrollViewcomponent 需要 2 个参数资产来控制其滚动:
您可以通过在Size inspector 中调整您的.xib 文件来控制此框架,或者您可以使用此类代码以编程方式进行:
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]。
你应该调整其内容的框架以确保它可以滚动,基本上你应该使用这个方法:
scrollView setContentSize:CGSizeMake(100, 200);
在这种情况下,您的 scrollView 将垂直滚动,因为它的高度内容大于其高度的框架。
您的代码示例
@property (atomic, retain) IBOutlet UIScrollView* scroll;
@synthesize scroll;
- (void)viewDidLoad {
[super viewDidLoad];
// Readjust your scroll frame
self.scroll.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
// Set its content size
self.scroll setContentSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height * 2);
// The following method is not necessary
// [self.view addSubview:self.scroll];
}