2010-04-26 99 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]; 

}