2013-03-15 84 views
0

我想添加一個滾動視圖到我的UIView,並把標籤,textview,圖像,但滾動條不顯示,我不能滾動。添加UIScrollView到UIView時不能滾動

//faux view 
UIView* fauxView = [[[UIView alloc] initWithFrame: CGRectMake(10, 10, 200, 200)]autorelease] ; 
[self.bgView addSubview: fauxView]; 

//the new panel 
self.bigPanelView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.frame.size.width, self.bgView.frame.size.height)]autorelease]; 
self.bigPanelView.center = CGPointMake(self.bgView.frame.size.width/2, self.bgView.frame.size.height/2); 
self.bigPanelView.backgroundColor = self.initialBackgroundColor; 


UIScrollView * scroll = [[UIScrollView alloc] initWithFrame:self.bigPanelView.bounds]; 
[scroll setContentSize:CGSizeMake(200, 200)]; 
[self.bigPanelView addSubview:scroll]; 
scroll.showsVerticalScrollIndicator = YES; 



// add label 

UILabel *lblTitle = [[[UILabel alloc] initWithFrame:CGRectMake(0, 25, self.bgView.frame.size.width, 46)]autorelease]; 
// If I change the 25 to 235 the label will come under the screen but still I cannot scroll. 
lblTitle.textAlignment = NSTextAlignmentCenter; // Align the label text in the center 
lblTitle.backgroundColor = [UIColor clearColor]; 
lblTitle.text = self.initialTitle; 
lblTitle.textColor = self.initialTitleColor; 
lblTitle.font = [UIFont systemFontOfSize:31]; 
[scroll addSubview: lblTitle]; 

回答

3

你必須要滾動視圖的contentSize超過視圖大小:

[scroll setContentSize:CGSizeMake(200, 200)]; 

需求是這樣的:

[scroll setContentSize:CGSizeMake(400, 400)]; 

當然,作出這樣的內容的大小,無論你」重新放置滾動視圖,這樣,它只會滾動,如果需要。

+0

我試過了,並將其設置爲400,400,但我仍然無法滾動垂直,水平滾動的作品。 – Shinonuma 2013-03-15 13:04:36

+0

400太小了,700以上更像是謝謝! – Shinonuma 2013-03-15 13:06:59

2

對於滾動 - scrollView的contentSize應該大於scrollView的框架。