2012-12-27 101 views
1

我的scrollView出現問題!我有一個名爲Rootview的視圖,我想爲scrollview添加三個子視圖。當我將scrollview作爲子視圖添加時,中間視圖和三個子視圖消失。這是我的代碼.. Rootview(整個窗口)和scrollview是網點。嘗試添加爲子視圖時,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]; 

任何人都可以幫助我嗎?

回答

0

的問題是,您不添加您隨時隨地middleScrollView

改變這種

[RootView addSubview:middleView]; 

[RootView addSubview:middleScrollView]; 
+0

對不起,我第一次forgott最後一行。我需要三個子視圖。當我嘗試將scrollview作爲子視圖添加到我的middleView並且其上的三個小視圖消失時,這一切都奏效了。 – user1932273

+0

我發現錯了。我將第一行更改爲UIView * middleView = [[UIView alloc] initWithFrame:CGRectMake(0,0,2024,218)];現在它工作.. – user1932273