2010-04-26 95 views
0

我在滚动视图中添加了一些表格和其他内容。滚动表格工作正常。但在父滚动视图中,当滚动时,会显示一个摇摆的垂直滚动条,有时甚至会到屏幕中间。有时显示在屏幕的左侧。而不限于垂直滚动条区域。当我设置showsVerticalScrollIndicator = NO时,没有显示。但是你知道滚动条为什么会移动吗?iPhone:TableView里面的UIScrollview,显示滚动条滚动条

DashboardView是UIScrollView的子类。

dashboard=[[DashboardView alloc] initWithFrame:fullScreenRect]; 
dashboard.contentSize = CGSizeMake(320,700); // must do! 
dashboard.showsVerticalScrollIndicator = YES; 
dashboard.bounces = YES; 
self.view = dashboard; 


@implementation DashboardView 

- (id)initWithFrame:(CGRect)frame { 
    if (self = [super initWithFrame:frame]) { 
     // Initialization code 
    } 
    return self; 
} 

- (void)drawRect:(CGRect)rect { 
    // Drawing code 
} 

- (void) layoutSubviews{ 

    NSArray *views = self.subviews; 

    [UIView beginAnimations:@"CollapseExpand" context:nil]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 

    UIView *view = [views objectAtIndex: 0]; 
    CGRect rect = view.frame; 

    for (int i = 1; i < [views count]; i++) {  
     view = [views objectAtIndex:i]; 
     view.frame = CGRectMake(rect.origin.x, rect.origin.y + rect.size.height, view.frame.size.width, view.frame.size.height); 
     rect = view.frame; 
    } 

    [UIView commitAnimations]; 

} 

回答

2

请记住,滚动条也是滚动的子视图。从views数组中排除它,然后再做一些处理。

+0

那是一个很好的点。谢谢。我现在就来看看。 – karim 2010-04-27 12:57:06

0

Yap。这解决了我的问题。看起来ScrollBars是一种UIImageView。如果有人需要它,这是我的新代码工作正常。

(void) layoutSubviews{ 

NSArray *views = self.subviews; 

[UIView beginAnimations:@"CollapseExpand" context:nil]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 

//CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];  
// [self.view insertSubview:balanceView belowSubview:profileView]; 


UIView *view = [views objectAtIndex: 0]; 
CGRect rect = view.frame; 

for (int i = 1; i < [views count]; i++) {  
    view = [views objectAtIndex:i]; 
    if ([view isMemberOfClass: [UIView class] ]) { 
     //CFShow(view); 
     view.frame = CGRectMake(rect.origin.x, rect.origin.y + rect.size.height, view.frame.size.width, view.frame.size.height); 
     rect = view.frame;   
    } 

} 

[UIView commitAnimations]; 

}