2013-03-15 117 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的框架。

相关问题