尝试添加为子视图时,ScrollView无法正常工作

时间:2012-12-27 14:15:47

标签: objective-c scrollview addsubview

我的scrollView有问题!我有一个名为Rootview的视图,我想在滚动视图中添加三个子视图。当我将scrollview添加为子视图时,中间视图和三个子视图消失。这是我的代码.. Rootview(整个窗口)和scrollview都是出口。

UIView *middleView = [[UIView alloc] initWithFrame:CGRectMake(0, 218, 2024, 218)];
[middleView setBackgroundColor: [UIColor yellowColor]];
[RootView addSubview:middleView];

//create new views for sap systems beginning from left

UIView *firstSystem1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 218)];
[firstSystem1 setBackgroundColor: [UIColor grayColor]];
[middleView addSubview:firstSystem1];

UIView *secondSystem1 = [[UIView alloc] initWithFrame:CGRectMake(305, 0, 300, 218)];
[secondSystem1 setBackgroundColor: [UIColor grayColor]];
[middleView addSubview:secondSystem1];

UIView *thirdSystem1 = [[UIView alloc] initWithFrame:CGRectMake(610, 0, 300, 218)];
[thirdSystem1 setBackgroundColor: [UIColor grayColor]];
[middleView addSubview:thirdSystem1];




CGSize scrollViewContentSize1 = CGSizeMake(2024, 218);

 [middleScrollView setContentSize:scrollViewContentSize1];
[middleScrollView addSubview:middleView];

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

问题是您没有将middleScrollView添加到任何地方

更改此

[RootView addSubview:middleView];

这个

[RootView addSubview:middleScrollView];