views:

236

answers:

2

Hi, I have added some table and other vies in a scrollview. scrolling in tables are working fine. But in the parent scrollview, when scrolling, a vacillating vertical scrollbars are shown, sometimes it even come to the middle of the screen. sometime show at the left side of the screen. and not limited to the vertical scrollbar region. When I set the showsVerticalScrollIndicator = NO, it is not shown. But do you know why the scrollbar is moving around.

DashboardView is a subclass of 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];

}
+1  A: 

Remember that scrollbars is subviews of scroll too. Exclude it from views array, before doing something with views.

Skie
thats a good point. thanks. i'll look into that now.
karim
A: 

Yap. that solved my problem. It seems Scrollbars are a kind of UIImageView. If anybody need it, this is my new code which works fine.

(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];

}

karim